@@ -13,10 +13,6 @@ which `@temporalio/lambda-worker` automatically detects and uses to produce stru
1313logs that CloudWatch Logs can parse natively. If you don't need structured logging, you can
1414remove the dependency and the SDK will fall back to its default human-readable logger.
1515
16- > ** Note:** ` @temporalio/lambda-worker ` is not yet published. The ` package.json ` currently
17- > references it via a local ` file: ` path to ` ../../sdk-node/packages/lambda-worker ` .
18- > TODO: Replace with a versioned dependency (e.g. ` ^1.15.0 ` ) once the package is published.
19-
2016## Prerequisites
2117
2218- A [ Temporal Cloud] ( https://temporal.io/cloud ) namespace (or a self-hosted Temporal
@@ -29,29 +25,46 @@ remove the dependency and the SDK will fall back to its default human-readable l
2925
3026## Files
3127
32- | File | Description |
33- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
28+ | File | Description |
29+ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
3430| ` src/index.ts ` | Lambda entry point — configures the worker, registers Workflows/Activities, enables OTel, and exports the handler |
35- | ` src/workflows.ts ` | Sample Workflow that executes a greeting Activity |
36- | ` src/activities.ts ` | Sample Activity that returns a greeting string |
37- | ` src/client.ts ` | Helper program to start a Workflow execution from a local machine |
38- | ` src/scripts/build-workflow-bundle.ts ` | Pre-bundles Workflow code with OTel interceptor modules for Lambda cold start performance |
39- | ` temporal.toml ` | Temporal client connection configuration (update with your namespace) |
40- | ` otel-collector-config.yaml ` | OpenTelemetry Collector configuration for ADOT (routes metrics to CloudWatch, traces to X-Ray) |
41- | ` deploy-lambda.sh ` | Packages and deploys the Lambda function |
42- | ` mk-iam-role.sh ` | Creates the IAM role that allows Temporal Cloud to invoke the Lambda |
43- | ` iam-role-for-temporal-lambda-invoke-test.yaml ` | CloudFormation template for the IAM role |
44- | ` extra-setup-steps ` | Additional IAM and Lambda configuration for OpenTelemetry support |
31+ | ` src/workflows.ts ` | Sample Workflow that executes a greeting Activity |
32+ | ` src/activities.ts ` | Sample Activity that returns a greeting string |
33+ | ` src/client.ts ` | Helper program to start a Workflow execution from a local machine |
34+ | ` src/scripts/build-workflow-bundle.ts ` | Pre-bundles Workflow code with OTel interceptor modules for Lambda cold start performance |
35+ | ` temporal.toml ` | Temporal client connection configuration (update with your namespace) |
36+ | ` otel-collector-config.yaml ` | OpenTelemetry Collector configuration for ADOT (routes metrics to CloudWatch, traces to X-Ray) |
37+ | ` deploy-lambda.sh ` | Packages and deploys the Lambda function |
38+ | ` mk-iam-role.sh ` | Creates the IAM role that allows Temporal Cloud to invoke the Lambda |
39+ | ` iam-role-for-temporal-lambda-invoke-test.yaml ` | CloudFormation template for the IAM role |
40+ | ` extra-setup-steps ` | Additional IAM and Lambda configuration for OpenTelemetry support |
4541
4642## Setup
4743
48- ### 1. Configure Temporal connection
44+ The instructions here are a slimmed down version of the more complete getting started guide which
45+ you can find [ here] ( https://docs.temporal.io/production-deployment/worker-deployments/serverless-workers/aws-lambda ) .
46+
47+ ### 1. Create a lambda function for your TypeScript worker
48+
49+ Use either the AWS web UI or CLI to create a Node.js runtime Lambda function. Ex:
50+
51+ ``` bash
52+ aws lambda create-function \
53+ --function-name my-temporal-worker \
54+ --runtime nodejs22.x \
55+ --handler lib/index.handler \
56+ --role arn:aws:iam::< YOUR_ACCOUNT_ID> :role/my-temporal-worker-execution \
57+ --timeout 600 \
58+ --memory-size 256
59+ ```
60+
61+ ### 2. Configure Temporal connection
4962
5063Edit ` temporal.toml ` with your Temporal Cloud namespace address and credentials. In production,
5164we'd recommend reading your credentials from a secret store, but to keep this example simple
5265the toml file defaults to reading them from keys bundled along with the Lambda code.
5366
54- ### 2 . Create the IAM role
67+ ### 3 . Create the IAM role
5568
5669This creates the IAM role that Temporal Cloud assumes to invoke your Lambda function:
5770
@@ -62,57 +75,24 @@ This creates the IAM role that Temporal Cloud assumes to invoke your Lambda func
6275The External ID is provided by Temporal Cloud in your namespace's serverless worker
6376configuration.
6477
65- ### 3. (Optional) Enable OpenTelemetry
66-
67- The sample calls ` applyDefaults(config) ` in the handler, which registers Temporal SDK
68- interceptors for tracing Workflow, Activity, and Nexus calls, and configures the Core SDK
69- to export metrics via OTLP. To complete the setup, attach two ADOT Lambda layers:
70-
71- 1 . ** ADOT JavaScript layer** — auto-instruments the handler and exports Node.js-side
72- traces to X-Ray. See [ this page] ( https://aws-otel.github.io/docs/getting-started/lambda/lambda-js )
73- for the layer ARN for your region.
74- 2 . ** ADOT Collector layer** (` aws-otel-collector-amd64 ` ) — runs the OTel Collector as a
75- Lambda extension, receiving Temporal Core SDK metrics via OTLP and forwarding them to
76- CloudWatch/X-Ray. See [ this page] ( https://aws-otel.github.io/docs/getting-started/lambda )
77- for the layer ARN.
78-
79- Update ` otel-collector-config.yaml ` with your function name and region, then set the
80- following environment variables on your Lambda:
81-
82- ```
83- AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument
84- OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/otel-collector-config.yaml
85- ```
86-
87- ` AWS_LAMBDA_EXEC_WRAPPER ` enables the JS layer's auto-instrumentation.
88- ` OPENTELEMETRY_COLLECTOR_CONFIG_URI ` points the collector at the custom config that
89- routes metrics to CloudWatch EMF and traces to X-Ray.
78+ ### 4. (Optional) Enable OpenTelemetry
9079
91- Enable X-Ray active tracing on the Lambda function (required for traces to appear):
92-
93- ``` bash
94- aws lambda update-function-configuration --function-name < function-name > \
95- --tracing-config Mode=Active
96- ```
80+ If you want traces, metrics, and logs, you'll have to attach the ADOT layer to your Lambda function.
81+ You will need to add the appropriate layer for your runtime and region. See [ this page
82+ ] ( https://aws-otel.github.io/docs/getting-started/lambda#getting-started-with-aws-lambda-layers )
83+ for more info. See also the [ Temporal docs on adding observability
84+ ] ( https://docs.temporal.io/develop/typescript/workers/serverless-workers/aws-lambda#add-observability )
85+ for additional TypeScript-specific configuration.
9786
9887Then run the extra setup to grant the Lambda role the necessary permissions:
9988
10089``` bash
10190./extra-setup-steps < role-name> < function-name> < region> < account-id>
10291```
10392
104- ### 4. Deploy the Lambda function
93+ Update ` otel-collector-config.yaml ` with your function name and region as needed.
10594
106- Create a Lambda function in AWS with:
107-
108- - ** Runtime** : Node.js >=20
109- - ** Handler** : ` index.handler ` (the default)
110- - ** Architecture** : x86_64
111-
112- It's likely you will need to increase the default memory limit in AWS for your lambda. A minimum of
113- 256MB is recommended.
114-
115- Then deploy:
95+ ### 5. Deploy the Lambda function
11696
11797``` bash
11898./deploy-lambda.sh < function-name>
@@ -121,7 +101,11 @@ Then deploy:
121101This compiles TypeScript, pre-bundles Workflow code, packages everything with dependencies,
122102and uploads to AWS Lambda.
123103
124- ### 5. Start a Workflow
104+ ### 6. Configure Temporal to be able to invoke your lambda function
105+
106+ Refer to the docs [ here] ( https://docs.temporal.io/production-deployment/worker-deployments/serverless-workers/aws-lambda#create-worker-deployment-version ) .
107+
108+ ### 7. Start a Workflow
125109
126110Use the starter program to execute a Workflow on the Lambda worker, using
127111the same config file the Lambda uses for connecting to the server:
0 commit comments