Skip to content

Commit 9606fad

Browse files
committed
fix: put back terraform as a deployment option
1 parent a633dfa commit 9606fad

File tree

6 files changed

+110
-5
lines changed

6 files changed

+110
-5
lines changed

nodejs/sample-apps/aws-sdk/README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff 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

2748
If 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
```
5071
6. **Attach the Node.js instrumentation layer**
5172
- Refer to the latest ARN in the OpenTelemetry Lambda releases, ie:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

nodejs/sample-apps/aws-sdk/lib/otel-sample-lambda-stack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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',

nodejs/sample-apps/aws-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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",

0 commit comments

Comments
 (0)