Skip to content

Commit 5d09293

Browse files
authored
Merge pull request #395 from dmitchsplunk/main
Add code for lambda workshop and update instructions
2 parents a27b012 + 1e8a487 commit 5d09293

24 files changed

+1091
-38
lines changed

content/en/ninja-workshops/6-lambda-kinesis/1-setup.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ weight: 1
99
## Prerequisites
1010

1111
### Observability Workshop Instance
12-
The Observability Workshop is most often completed on a Splunk-issued and preconfigured EC2 instance running Ubuntu.
12+
The Observability Workshop uses the `Splunk4Ninjas - Observability` workshop template in Splunk Show,
13+
which provides a pre-configured EC2 instance running Ubuntu.
1314

1415
Your workshop instructor will provide you with the credentials to your assigned workshop instance.
1516

@@ -66,19 +67,14 @@ Your Splunk-issued workshop instance should already have **terraform** installed
6667
sudo apt update && sudo apt install terraform
6768
```
6869

69-
### Workshop Directory (o11y-lambda-workshop)
70-
The Workshop Directory `o11y-lambda-workshop` is a repository that contains all the configuration files and scripts to complete both the auto-instrumentation and manual instrumentation of the example Lambda-based application we will be using today.
70+
### Workshop Directory (lambda)
71+
The Workshop Directory `lambda` is a repository that contains all the configuration files and scripts to complete both the auto-instrumentation and manual instrumentation of the example Lambda-based application we will be using today.
7172

7273
- Confirm you have the workshop directory in your home directory:
7374
```bash
74-
cd && ls
75-
```
76-
- _The expected output would include **o11y-lambda-workshop**_
77-
78-
- If the **o11y-lambda-workshop** directory is not in your home directory, clone it with the following command:
79-
```bash
80-
git clone https://github.com/gkono-splunk/o11y-lambda-workshop.git
75+
cd ~/workshop && ls
8176
```
77+
- _The expected output would include **lambda**_
8278

8379
### AWS & Terraform Variables
8480

@@ -92,7 +88,7 @@ The AWS CLI requires that you have credentials to be able to access and manage r
9288
- _This command should provide a prompt similar to the one below:_
9389
```bash
9490
AWS Access Key ID [None]: XXXXXXXXXXXXXXXX
95-
AWS Secret Acces Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
91+
AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9692
Default region name [None]: us-east-1
9793
Default outoput format [None]:
9894
```
@@ -102,6 +98,11 @@ The AWS CLI requires that you have credentials to be able to access and manage r
10298
aws configure
10399
```
104100

101+
> Note to the workshop instructor: create a new user in the target AWS account called `lambda-workshop-user`.
102+
> Ensure it has full permissions to perform the required actions via Terraform. Create an access token for the `lambda-workshop-user`
103+
> user and share the Access Key ID and Secret Access Key with the workshop participants. Delete the user
104+
> when the workshop is complete.
105+
105106
#### Terraform
106107
Terraform supports the passing of variables to ensure sensitive or dynamic data is not hard-coded in your .tf configuration files, as well as to make those values reusable throughout your resource definitions.
107108

@@ -118,7 +119,7 @@ We will be using a combination of _**variables.tf**_ and _**terraform.tfvars**_
118119

119120
- Using either **vi** or **nano**, open the _**terraform.tfvars**_ file in either the **auto** or **manual** directory
120121
```bash
121-
vi ~/o11y-lambda-workshop/auto/terraform.tfvars
122+
vi ~/workshop/lambda/auto/terraform.tfvars
122123
```
123124
- Set the variables with their values. Replace the **CHANGEME** placeholders with those provided by your instructor.
124125
```bash
@@ -128,22 +129,23 @@ We will be using a combination of _**variables.tf**_ and _**terraform.tfvars**_
128129
prefix = "CHANGEME"
129130
```
130131
- _Ensure you change only the placeholders, leaving the quotes and brackets intact, where applicable._
132+
- _For the **otel_lambda_layer**, use the value for **us-east-1** found [here](https://github.com/signalfx/lambda-layer-versions/blob/main/splunk-apm/splunk-apm.md)
131133
- _The _**prefix**_ is a unique identifier you can choose for yourself, to make your resources distinct from other participants' resources. We suggest using a short form of your name, for example._
132-
- _Also, please only lowercase letters for the **prefix**. Certain resouces in AWS, such as S3, would through an error if you use uppercase letters._
134+
- _Also, please only lowercase letters for the **prefix**. Certain resources in AWS, such as S3, would through an error if you use uppercase letters._
133135
- Save your file and exit the editor.
134136
- Finally, copy the _**terraform.tfvars**_ file you just edited to the other directory.
135137
```bash
136-
cp ~/o11y-lambda-workshop/auto/terraform.tfvars ~/o11y-lambda-workshop/manual
138+
cp ~/workshop/lambda/auto/terraform.tfvars ~/workshop/lambda/manual
137139
```
138140
- _We do this as we will be using the same values for both the autoinstrumentation and manual instrumentation protions of the workshop_
139141
140142
### File Permissions
141143
142144
While all other files are fine as they are, the **send_message.py** script in both the `auto` and `manual` will have to be executed as part of our workshop. As a result, it needs to have the appropriate permissions to run as expected. Follow these instructions to set them.
143145
144-
- First, ensure you are in the `o11y-lambda-workshop` directory:
146+
- First, ensure you are in the `lambda` directory:
145147
```bash
146-
cd ~/o11y-lambda-workshop
148+
cd ~/workshop/lambda
147149
```
148150
149151
- Next, run the following command to set executable permissions on the `send_message.py` script:

content/en/ninja-workshops/6-lambda-kinesis/2-auto-instrumentation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ weight: 2
77
The first part of our workshop will demonstrate how auto-instrumentation with OpenTelemetry allows the OpenTelemetry Collector to auto-detect what language your function is written in, and start capturing traces for those functions.
88

99
### The Auto-Instrumentation Workshop Directory & Contents
10-
First, let us take a look at the `o11y-lambda-workshop/auto` directory, and some of its files. This is where all the content for the auto-instrumentation portion of our workshop resides.
10+
First, let us take a look at the `workshop/lambda/auto` directory, and some of its files. This is where all the content for the auto-instrumentation portion of our workshop resides.
1111

1212
#### The `auto` Directory
13-
- Run the following command to get into the **o11y-lambda-workshop/auto** directory:
13+
- Run the following command to get into the **workshop/lambda/auto** directory:
1414
```bash
15-
cd ~/o11y-lambda-workshop/auto
15+
cd ~/workshop/lambda/auto
1616
```
1717

1818
- Inspect the contents of this directory:
@@ -114,11 +114,11 @@ In order to deploy the resources defined in the `main.tf` file, you first need t
114114
```bash
115115
pwd
116116
```
117-
- _The expected output would be **~/o11y-lambda-workshop/auto**_
117+
- _The expected output would be **~/workshop/lambda/auto**_
118118

119119
- If you are not in the `auto` directory, run the following command:
120120
```bash
121-
cd ~/o11y-lambda-workshop/auto
121+
cd ~/workshop/lambda/auto
122122
```
123123

124124
- Run the following command to initialize Terraform in this directory
@@ -172,11 +172,11 @@ To start getting some traces from our deployed Lambda functions, we would need t
172172
```bash
173173
pwd
174174
```
175-
- _The expected output would be **~/o11y-lambda-workshop/auto**_
175+
- _The expected output would be **~/workshop/lambda/auto**_
176176

177177
- If you are not in the `auto` directory, run the following command
178178
```bash
179-
cd ~/o11y-lambda-workshop/auto
179+
cd ~/workshop/lambda/auto
180180
```
181181

182182
The `send_message.py` script is a Python script that will take input at the command line, add it to a JSON dictionary, and send it to your `producer-lambda` function's endpoint repeatedly, as part of a while loop.

content/en/ninja-workshops/6-lambda-kinesis/3-lambdas-in-splunk.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ Please follow these steps to destroy your resources:
8686
pwd
8787
```
8888

89-
- _The expected output would be **~/o11y-lambda-workshop/auto**_
89+
- _The expected output would be **~/workshop/lambda/auto**_
9090

9191
- If you are not in the `auto` directory, run the following command:
9292

9393
```bash
94-
cd ~/o11y-lambda-workshop/auto
94+
cd ~/workshop/lambda/auto
9595
```
9696

9797
- Destroy the Lambda functions and other AWS resources you deployed earlier:

content/en/ninja-workshops/6-lambda-kinesis/4-manual-instrumentation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ The second part of our workshop will focus on demonstrating how manual instrumen
88

99
### The Manual Instrumentation Workshop Directory & Contents
1010

11-
Once again, we will first start by taking a look at our operating directory, and some of its files. This time, it will be `o11y-lambda-workshop/manual` directory. This is where all the content for the manual instrumentation portion of our workshop resides.
11+
Once again, we will first start by taking a look at our operating directory, and some of its files. This time, it will be `workshop/lambda/manual` directory. This is where all the content for the manual instrumentation portion of our workshop resides.
1212

1313
#### The `manual` directory
1414

15-
- Run the following command to get into the `o11y-lambda-workshop/manual` directory:
15+
- Run the following command to get into the `workshop/lambda/manual` directory:
1616

1717
```bash
18-
cd ~/o11y-lambda-workshop/manual
18+
cd ~/workshop/lambda/manual
1919
```
2020

2121
- Inspect the contents of this directory with the `ls` command:
@@ -42,23 +42,23 @@ Let's make sure that all these files that LOOK the same, are actually the same.
4242
- Compare the `main.tf` files in the `auto` and `manual` directories:
4343
4444
```bash
45-
diff ~/o11y-lambda-workshop/auto/main.tf ~/o11y-lambda-workshop/manual/main.tf
45+
diff ~/workshop/lambda/auto/main.tf ~/workshop/lambda/manual/main.tf
4646
```
4747
4848
- There is no difference! _(Well, there shouldn't be. Ask your workshop facilitator to assist you if there is)_
4949

5050
- Now, let's compare the `producer.mjs` files:
5151
5252
```bash
53-
diff ~/o11y-lambda-workshop/auto/handler/producer.mjs ~/o11y-lambda-workshop/manual/handler/producer.mjs
53+
diff ~/workshop/lambda/auto/handler/producer.mjs ~/workshop/lambda/manual/handler/producer.mjs
5454
```
5555
5656
- There's quite a few differences here!
5757

5858
- You may wish to view the entire file and examine its content
5959

6060
```bash
61-
cat ~/o11y-lambda-workshop/handler/producer.mjs
61+
cat ~/workshop/lambda/manual/handler/producer.mjs
6262
```
6363

6464
- Notice how we are now importing some OpenTelemetry objects directly into our function to handle some of the manual instrumentation tasks we require.
@@ -75,7 +75,7 @@ Let's make sure that all these files that LOOK the same, are actually the same.
7575
- Finally, compare the `consumer.mjs` files:
7676
7777
```bash
78-
diff ~/o11y-lambda-workshop/auto/handler/consumer.mjs ~/o11y-lambda-workshop/manual/handler/consumer.mjs
78+
diff ~/workshop/lambda/auto/handler/consumer.mjs ~/workshop/lambda/manual/handler/consumer.mjs
7979
```
8080
8181
- Here also, there are a few differences of note. Let's take a closer look

content/en/ninja-workshops/6-lambda-kinesis/5-redeploy-lambdas.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ Seeing as we're in a new directory, we will need to initialize Terraform here on
1616
pwd
1717
```
1818

19-
- _The expected output would be **~/o11y-lambda-workshop/manual**_
19+
- _The expected output would be **~/workshop/lambda/manual**_
2020

2121
- If you are not in the `manual` directory, run the following command:
2222

2323
```bash
24-
cd ~/o11y-lambda-workshop/manual
24+
cd ~/workshop/lambda/manual
2525
```
2626

2727
- Run the following command to initialize Terraform in this directory
@@ -72,12 +72,12 @@ Once more, we will send our `name` and `superpower` as a message to our endpoint
7272
pwd
7373
```
7474

75-
- _The expected output would be **~/o11y-lambda-workshop/manual**_
75+
- _The expected output would be **~/workshop/lambda/manual**_
7676

7777
- If you are not in the `manual` directory, run the following command:
7878

7979
```bash
80-
cd ~/o11y-lambda-workshop/manual
80+
cd ~/workshop/lambda/manual
8181
```
8282

8383
- Run the `send_message.py` script as a background process:

content/en/ninja-workshops/6-lambda-kinesis/6-updated-lambdas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ Please follow these steps to destroy your resources:
9393
pwd
9494
```
9595

96-
- _The expected output would be **~/o11y-lambda-workshop/manual**_
96+
- _The expected output would be **~/workshop/lambda/manual**_
9797

9898
- If you are not in the `manual` directory, run the following command:
9999

100100
```bash
101-
cd ~/o11y-lambda-workshop/manual
101+
cd ~/workshop/lambda/manual
102102
```
103103

104104
- Destroy the Lambda functions and other AWS resources you deployed earlier:

workshop/lambda/auto/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!terraform.tfvars
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Lambda Consumer App for Kinesis Stream
2+
3+
// Lambda Consumer
4+
const consumer = async( event ) => {
5+
try{
6+
for( const record of event.Records ) {
7+
const payload = record.kinesis;
8+
const message = Buffer.from(payload.data, 'base64').toString();
9+
10+
console.log(
11+
`Kinesis Message:
12+
partition key: ${payload.partitionKey}
13+
sequence number: ${payload.sequenceNumber}
14+
kinesis schema version: ${payload.kinesisSchemaVersion}
15+
data: ${message}`
16+
);
17+
}
18+
} catch ( error ) {
19+
console.log(error);
20+
}
21+
};
22+
23+
export { consumer };
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Lambda Producer App for Kinesis Stream
2+
import { KinesisClient, PutRecordCommand } from "@aws-sdk/client-kinesis";
3+
4+
5+
// Lambda Producer
6+
const producer = async( event ) => {
7+
const kinesis = new KinesisClient({});
8+
9+
let statusCode = 200;
10+
let message;
11+
12+
if (!event.body) {
13+
return {
14+
statusCode: 400,
15+
body: JSON.stringify({
16+
message: "No message body found",
17+
}),
18+
};
19+
}
20+
21+
const streamName = process.env.KINESIS_STREAM;
22+
23+
try {
24+
await kinesis.send(
25+
new PutRecordCommand({
26+
StreamName: streamName,
27+
PartitionKey: "1234",
28+
Data: event.body,
29+
}),
30+
31+
message = `Message placed in the Event Stream: ${streamName}`
32+
)
33+
} catch ( error ) {
34+
console.log(error);
35+
message = error;
36+
statusCode = 500;
37+
}
38+
39+
return {
40+
statusCode,
41+
body: JSON.stringify({
42+
message,
43+
}),
44+
};
45+
};
46+
47+
export { producer };

0 commit comments

Comments
 (0)