|
1 |
| -# AWS SDK Sample Application |
| 1 | +# 🧪 AWS SDK Sample Application with OpenTelemetry |
2 | 2 |
|
3 |
| -**This Sample App is a work-in-progress because it depends on the OpenTelemetry public layer. The public layer will not be published |
| 3 | +This sample demonstrates how to use the **AWS SDK** within a Lambda function with **OpenTelemetry (OTel)** capabilities. It performs a simple `STS GetCallerIdentity` call for demonstration purposes and outputs Otel telemetry data to logs. |
4 | 4 |
|
5 |
| -This sample application demonstrates usage of the AWS SDK. To try it out, make sure the collector and nodejs Lambda |
6 |
| -layers are built. |
| 5 | +Example log output: |
| 6 | + |
7 | 7 |
|
8 |
| -In [collector](../../../collector), run `make package`. |
9 |
| -In [nodejs](../../), run `npm install`. |
| 8 | +--- |
10 | 9 |
|
11 |
| -Then, run `terraform init` and `terraform apply`. The lambda function will be initialized and the URL for an API Gateway invoking the Lambda |
12 |
| -will be displayed at the end. Send a request to the URL in a browser or using curl to execute the function. Then, |
13 |
| -navigate to the function's logs [here](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logStream:group=%252Faws%252Flambda%252Fhello-nodejs). |
14 |
| -You will see a log stream with an event time corresponding to when you issued the request - open it and you can find |
15 |
| -information about the exported spans in the log stream. |
| 10 | +## 🚀 Deploy Using AWS CDK |
| 11 | + |
| 12 | +Follow these steps to deploy the demo stack via CDK: |
| 13 | + |
| 14 | +1. **Install dependencies** |
| 15 | + `npm install` |
| 16 | + |
| 17 | +2. **Bootstrap your AWS environment (if not done already)** |
| 18 | + `npx cdk bootstrap` |
| 19 | + |
| 20 | +3. **Deploy the stack** |
| 21 | + `npx cdk deploy OtelSampleLambdaStack` |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## 🚀 Deploy Using Terraform |
| 26 | + |
| 27 | +Follow these steps to deploy the demo stack via Terraform: |
| 28 | + |
| 29 | +1. **Install dependencies** |
| 30 | + `npm install` |
| 31 | + |
| 32 | +2. **Build the Lambda function artifact** |
| 33 | + `npm run build` |
| 34 | + |
| 35 | +3. **Move to deploy/wrapper folder** |
| 36 | + `cd deploy/wrapper` |
| 37 | + |
| 38 | +4. **Terraform init** |
| 39 | + `terraform init` |
| 40 | + |
| 41 | +5. **Terraform apply** |
| 42 | + `terraform apply` |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## 🛠️ Manual Deployment via AWS Console |
| 47 | + |
| 48 | +If you'd prefer to deploy manually: |
| 49 | + |
| 50 | +1. **Install dependencies** |
| 51 | + `npm install` |
| 52 | + |
| 53 | +2. **Build the Lambda function artifact** |
| 54 | + `npm run build` |
| 55 | + |
| 56 | +3. **Create a new AWS Lambda function** |
| 57 | + - Runtime: Select the latest `nodejs.x` |
| 58 | + |
| 59 | +4. **Upload the artifact** |
| 60 | + - File location: `build/function.zip` |
| 61 | + |
| 62 | +5. **Set the following environment variables** |
| 63 | +``` |
| 64 | + OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318/ |
| 65 | + OTEL_TRACES_EXPORTER=console |
| 66 | + OTEL_METRICS_EXPORTER=console |
| 67 | + OTEL_LOG_LEVEL=INFO |
| 68 | + OTEL_TRACES_SAMPLER=always_on |
| 69 | + AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler |
| 70 | +``` |
| 71 | +6. **Attach the Node.js instrumentation layer** |
| 72 | + - Refer to the latest ARN in the OpenTelemetry Lambda releases, ie: |
| 73 | + https://github.com/open-telemetry/opentelemetry-lambda/releases/tag/layer-nodejs%2F0.14.0 |
| 74 | + |
| 75 | +7. **Attach the OpenTelemetry Collector layer** |
| 76 | + - Refer to the ARN in the release notes, ie: |
| 77 | + https://github.com/open-telemetry/opentelemetry-lambda/releases/tag/layer-collector%2F0.15.0 |
0 commit comments