File tree Expand file tree Collapse file tree 6 files changed +110
-5
lines changed
nodejs/sample-apps/aws-sdk Expand file tree Collapse file tree 6 files changed +110
-5
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,27 @@ Follow these steps to deploy the demo stack via CDK:
2222
2323---
2424
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+
2546## 🛠️ Manual Deployment via AWS Console
2647
2748If you'd prefer to deploy manually:
@@ -43,9 +64,9 @@ If you'd prefer to deploy manually:
4364 OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318/
4465 OTEL_TRACES_EXPORTER=console
4566 OTEL_METRICS_EXPORTER=console
46- OTEL_LOG_LEVEL=INFO
47- OTEL_TRACES_SAMPLER=always_on
48- AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
67+ OTEL_LOG_LEVEL=INFO
68+ OTEL_TRACES_SAMPLER=always_on
69+ AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
4970```
50716 . ** Attach the Node.js instrumentation layer**
5172 - Refer to the latest ARN in the OpenTelemetry Lambda releases, ie:
Original file line number Diff line number Diff line change 1+ locals {
2+ collector_layer_arn = " arn:aws:lambda:${ data . aws_region . current . name } :${ var . account_id } :layer:opentelemetry-collector-arm64-0_15_0:1"
3+ sdk_layer_arn = " arn:aws:lambda:${ data . aws_region . current . name } :${ var . account_id } :layer:opentelemetry-nodejs-0_14_0:1"
4+ }
5+
6+ data "aws_region" "current" {}
7+
8+ module "hello-lambda-function" {
9+ source = " terraform-aws-modules/lambda/aws"
10+ version = " 7.21.0"
11+
12+ architectures = compact ([var . architecture ])
13+ function_name = var. name
14+ handler = " index.handler"
15+ runtime = var. runtime
16+
17+ create_package = false
18+ local_existing_package = " ${ path . module } /../../build/function.zip"
19+
20+ memory_size = 384
21+ timeout = 20
22+
23+ layers = compact ([
24+ local . collector_layer_arn ,
25+ local . sdk_layer_arn
26+ ])
27+
28+ environment_variables = {
29+ AWS_LAMBDA_EXEC_WRAPPER = " /opt/otel-handler"
30+ OTEL_TRACES_EXPORTER = " console"
31+ OTEL_METRICS_EXPORTER = " console"
32+ OTEL_LOG_LEVEL = " DEBUG"
33+ OTEL_EXPORTER_OTLP_ENDPOINT = " http://localhost:4318/"
34+ OTEL_TRACES_SAMPLER = " always_on"
35+ }
36+
37+ tracing_mode = var. tracing_mode
38+ }
39+
40+ module "api-gateway" {
41+ source = " ../../../../../utils/terraform/api-gateway-proxy"
42+
43+ name = var. name
44+ function_name = module. hello-lambda-function . lambda_function_name
45+ function_invoke_arn = module. hello-lambda-function . lambda_function_invoke_arn
46+ enable_xray_tracing = var. tracing_mode == " Active"
47+ }
Original file line number Diff line number Diff line change 1+ output "api-gateway-url" {
2+ value = module. api-gateway . api_gateway_url
3+ }
4+
5+ output "function_role_name" {
6+ value = module. hello-lambda-function . lambda_role_name
7+ }
Original file line number Diff line number Diff line change 1+ variable "name" {
2+ type = string
3+ description = " Name of created function and API Gateway"
4+ default = " hello-nodejs-awssdk"
5+ }
6+
7+ variable "account_id" {
8+ type = string
9+ description = " AWS account ID where the Lambda layers are published"
10+ default = " 184161586896"
11+ }
12+
13+ variable "tracing_mode" {
14+ type = string
15+ description = " Lambda function tracing mode"
16+ default = " PassThrough"
17+ }
18+
19+ variable "architecture" {
20+ type = string
21+ description = " Lambda function architecture, valid values are arm64 or x86_64"
22+ default = " arm64"
23+ }
24+
25+ variable "runtime" {
26+ type = string
27+ description = " NodeJS runtime version used for sample Lambda Function"
28+ default = " nodejs22.x"
29+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export class OtelSampleLambdaStack extends cdk.Stack {
1010 super ( scope , id , props ) ;
1111
1212 const region = cdk . Stack . of ( this ) . region ;
13- const architecture = 'amd64' ; // or 'arm64' for ARM architecture
13+ const architecture = lambda . Architecture . ARM_64 ;
1414 const collectorLayerArn = `arn:aws:lambda:${ region } :${ AWS_ACCOUNT_ID } :layer:opentelemetry-collector-${ architecture } -0_15_0:1` ; // Update with the latest version if needed
1515 const nodejsInstrumentationLayerArn = `arn:aws:lambda:${ region } :${ AWS_ACCOUNT_ID } :layer:opentelemetry-nodejs-0_14_0:1` ; // Update with the latest version if needed
1616
@@ -24,6 +24,7 @@ export class OtelSampleLambdaStack extends cdk.Stack {
2424 ] ,
2525 timeout : cdk . Duration . seconds ( 30 ) ,
2626 memorySize : 256 ,
27+ architecture,
2728 environment : {
2829 OTEL_EXPORTER_OTLP_ENDPOINT : 'http://localhost:4318/' ,
2930 OTEL_TRACES_EXPORTER : 'console' ,
Original file line number Diff line number Diff line change 1212 "lint:fix" : " ESLINT_USE_FLAT_CONFIG=false eslint . --ext .ts --fix" ,
1313 "build" : " npm run clean && npm run compile && npm run postcompile" ,
1414 "compile" : " tsc -p ." ,
15- "postcompile" : " copyfiles 'package*.json' build/src / && npm install --production --ignore-scripts --prefix build/src / && cd build/src && bestzip ../function.zip *"
15+ "postcompile" : " copyfiles 'package*.json' build/lambda / && npm install --production --ignore-scripts --prefix build/lambda / && cd build/lambda && bestzip ../function.zip *"
1616 },
1717 "keywords" : [
1818 " opentelemetry" ,
You can’t perform that action at this time.
0 commit comments