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.
Follow these steps to deploy the demo stack via CDK:
-
Install dependencies
npm install -
Bootstrap your AWS environment (if not done already)
npx cdk bootstrap -
Deploy the stack
npx cdk deploy OtelSampleLambdaStack
Follow these steps to deploy the demo stack via Terraform:
-
Install dependencies
npm install -
Build the Lambda function artifact
npm run build -
Move to deploy/wrapper folder
cd deploy/wrapper -
Terraform init
terraform init -
Terraform apply
terraform apply
If you'd prefer to deploy manually:
-
Install dependencies
npm install -
Build the Lambda function artifact
npm run build -
Create a new AWS Lambda function
- Runtime: Select the latest
nodejs.x
- Runtime: Select the latest
-
Upload the artifact
- File location:
build/function.zip
- File location:
-
Set the following environment variables
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318/
OTEL_TRACES_EXPORTER=console
OTEL_METRICS_EXPORTER=console
OTEL_LOG_LEVEL=INFO
OTEL_TRACES_SAMPLER=always_on
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
-
Attach the Node.js instrumentation layer
- Refer to the latest ARN in the OpenTelemetry Lambda releases, ie:
https://github.com/open-telemetry/opentelemetry-lambda/releases/tag/layer-nodejs%2F0.14.0
- Refer to the latest ARN in the OpenTelemetry Lambda releases, ie:
-
Attach the OpenTelemetry Collector layer
- Refer to the ARN in the release notes, ie:
https://github.com/open-telemetry/opentelemetry-lambda/releases/tag/layer-collector%2F0.15.0
- Refer to the ARN in the release notes, ie:
