Skip to content

Commit d92e572

Browse files
committed
Update to use published package & refer to docs
1 parent 462cd6d commit d92e572

4 files changed

Lines changed: 61 additions & 38 deletions

File tree

lambda_worker/README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,30 @@ any Workflow/Activity definitions.
3535

3636
## Setup
3737

38-
### 1. Configure Temporal connection
38+
The instructions here are a slimmed down version of the more complete getting started guide which
39+
you can find [here](https://docs.temporal.io/production-deployment/worker-deployments/serverless-workers/aws-lambda).
40+
41+
### 1. Create a lambda function for your Python worker
42+
43+
Use either the AWS web UI or CLI to create a Python runtime Lambda function. Ex:
44+
45+
```bash
46+
aws lambda create-function \
47+
--function-name my-temporal-worker \
48+
--runtime python3.13 \
49+
--handler lambda_function.lambda_handler \
50+
--role arn:aws:iam::<YOUR_ACCOUNT_ID>:role/my-temporal-worker-execution \
51+
--timeout 600 \
52+
--memory-size 256
53+
```
54+
55+
### 2. Configure Temporal connection
3956

4057
Edit `temporal.toml` with your Temporal Cloud namespace address and credentials. In production,
4158
we'd recommend reading your credentials from a secret store, but to keep this example simple
4259
the toml file defaults to reading them from keys bundled along with the Lambda code.
4360

44-
### 2. Create the IAM role
61+
### 3. Create the IAM role
4562

4663
This creates the IAM role that Temporal Cloud assumes to invoke your Lambda function:
4764

@@ -52,7 +69,7 @@ This creates the IAM role that Temporal Cloud assumes to invoke your Lambda func
5269
The External ID is provided by Temporal Cloud in your namespace's serverless worker
5370
configuration.
5471

55-
### 3. (Optional) Enable OpenTelemetry
72+
### 4. (Optional) Enable OpenTelemetry
5673

5774
If you want traces, metrics, and logs, you'll have to attach the ADOT layet to your Lambda function.
5875
You will need to add the appropriate layer for your runtime and region. See [this page
@@ -67,7 +84,7 @@ Then run the extra setup to grant the Lambda role the necessary permissions:
6784

6885
Update `otel-collector-config.yaml` with your function name and region as needed.
6986

70-
### 4. Deploy the Lambda function
87+
### 5. Deploy the Lambda function
7188

7289
```bash
7390
./deploy-lambda.sh <function-name>
@@ -76,7 +93,11 @@ Update `otel-collector-config.yaml` with your function name and region as needed
7693
This installs Python dependencies, bundles them with your code and configuration files,
7794
and uploads to AWS Lambda.
7895

79-
### 5. Start a Workflow
96+
### 6. Configure Temporal to be able to invoke your lambda function
97+
98+
Refer to the docs [here](https://docs.temporal.io/production-deployment/worker-deployments/serverless-workers/aws-lambda#create-worker-deployment-version).
99+
100+
### 7. Start a Workflow
80101

81102
Use the starter program to execute a Workflow on the Lambda worker, using
82103
the same config file the Lambda uses for connecting to the server:

lambda_worker/deploy-lambda.sh

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@ set -euo pipefail
33

44
FUNCTION_NAME="${1:?Usage: deploy-lambda.sh <function-name>}"
55
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6-
SDK_DIR="$SCRIPT_DIR/../../sdk-python"
76

8-
# Install the published temporalio package (Linux wheels) and OTel dependencies
9-
# TODO: Remove explicit OTel deps once lambda-worker-otel extra is published
10-
uv pip install --target "$SCRIPT_DIR/package" --python-platform x86_64-unknown-linux-gnu --no-build \
11-
temporalio \
12-
"opentelemetry-api>=1.11.1,<2" \
13-
"opentelemetry-sdk>=1.11.1,<2" \
14-
"opentelemetry-exporter-otlp-proto-grpc>=1.11.1,<2" \
15-
"opentelemetry-semantic-conventions>=0.40b0,<1" \
16-
"opentelemetry-sdk-extension-aws>=2.0.0,<3"
17-
18-
# Overlay the local SDK's pure-Python source (for unpublished contrib code)
19-
# TODO: Remove this step once the contrib package is published
20-
cp -r "$SDK_DIR/temporalio/contrib" "$SCRIPT_DIR/package/temporalio"
7+
# Install the published temporalio package (Linux wheels) with the OTel extras
8+
# needed by the lambda_worker contrib module
9+
uv pip install --target "$SCRIPT_DIR/package" --python-platform x86_64-unknown-linux-gnu \
10+
--only-binary=:all: "temporalio[lambda-worker-otel]"
2111

2212
# Copy application code into the package directory (all at zip root)
2313
cp "$SCRIPT_DIR/lambda_function.py" "$SCRIPT_DIR/workflows.py" \

lambda_worker/iam-role-for-temporal-lambda-invoke-test.yaml

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CloudFormation template for creating an IAM role that Temporal Cloud can assume to invoke Lambda functions.
22
AWSTemplateFormatVersion: "2010-09-09"
3-
Description: Creates an IAM role that Temporal Cloud can assume to invoke Lambda functions for Serverless Workers.
3+
Description: Creates an IAM role that Temporal Cloud can assume to invoke multiple Lambda functions for Serverless Workers.
44

55
Parameters:
66
AssumeRoleExternalId:
@@ -10,11 +10,15 @@ Parameters:
1010
MinLength: 5
1111
MaxLength: 45
1212

13-
LambdaFunctionARN:
14-
Type: String
13+
LambdaFunctionARNs:
14+
Type: CommaDelimitedList
1515
Description: >-
16-
The ARN of the Lambda function to invoke
17-
(e.g., arn:aws:lambda:us-west-2:123456789012:function:worker-1)
16+
Comma-separated list of Lambda function ARNs to invoke (e.g.,
17+
arn:aws:lambda:us-west-2:123456789012:function:worker-1,arn:aws:lambda:us-west-2:123456789012:function:worker-2)
18+
19+
RoleName:
20+
Type: String
21+
Default: "Temporal-Cloud-Serverless-Worker"
1822

1923
Metadata:
2024
AWS::CloudFormation::Interface:
@@ -26,26 +30,34 @@ Metadata:
2630
- Label:
2731
default: "Lambda Configuration"
2832
Parameters:
29-
- LambdaFunctionARN
33+
- LambdaFunctionARNs
34+
- RoleName
3035
ParameterLabels:
3136
AssumeRoleExternalId:
3237
default: "External ID (provided by Temporal Cloud)"
33-
LambdaFunctionARN:
34-
default: "Lambda Function ARN"
38+
LambdaFunctionARNs:
39+
default: "Lambda Function ARNs (comma-separated list)"
40+
RoleName:
41+
default: "IAM Role Name"
3542

3643
Resources:
3744
TemporalCloudServerlessWorker:
3845
Type: AWS::IAM::Role
3946
Properties:
40-
RoleName: !Sub
41-
- "Temporal-Cloud-Serverless-Worker-${LambdaName}"
42-
- LambdaName: !Select [6, !Split [":", !Ref LambdaFunctionARN]]
47+
RoleName: !Sub "${RoleName}-${AWS::StackName}"
4348
AssumeRolePolicyDocument:
4449
Version: "2012-10-17"
4550
Statement:
4651
- Effect: Allow
4752
Principal:
48-
AWS: [arn:aws:iam::031568301006:role/wci-lambda-invoke]
53+
AWS:
54+
[
55+
arn:aws:iam::902542641901:role/wci-lambda-invoke,
56+
arn:aws:iam::160190466495:role/wci-lambda-invoke,
57+
arn:aws:iam::819232936619:role/wci-lambda-invoke,
58+
arn:aws:iam::829909441867:role/wci-lambda-invoke,
59+
arn:aws:iam::354116250941:role/wci-lambda-invoke,
60+
]
4961
Action: sts:AssumeRole
5062
Condition:
5163
StringEquals:
@@ -65,9 +77,9 @@ Resources:
6577
Action:
6678
- lambda:InvokeFunction
6779
- lambda:GetFunction
68-
Resource: [!Ref LambdaFunctionARN]
80+
Resource: !Ref LambdaFunctionARNs
6981
Roles:
70-
- !Ref TemporalCloudServerlessWorker
82+
- !Sub "${RoleName}-${AWS::StackName}"
7183

7284
Outputs:
7385
RoleARN:
@@ -78,8 +90,8 @@ Outputs:
7890

7991
RoleName:
8092
Description: The name of the IAM role
81-
Value: !Ref TemporalCloudServerlessWorker
93+
Value: !Ref RoleName
8294

83-
LambdaFunctionARN:
84-
Description: The Lambda function ARN that can be invoked
85-
Value: !Ref LambdaFunctionARN
95+
LambdaFunctionARNs:
96+
Description: The Lambda function ARNs that can be invoked
97+
Value: !Join [", ", !Ref LambdaFunctionARNs]

lambda_worker/mk-iam-role.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ aws cloudformation create-stack \
1313
--template-body file://iam-role-for-temporal-lambda-invoke-test.yaml \
1414
--parameters \
1515
ParameterKey=AssumeRoleExternalId,ParameterValue="$EXTERNAL_ID" \
16-
ParameterKey=LambdaFunctionARN,ParameterValue="$LAMBDA_ARN" \
16+
ParameterKey=LambdaFunctionARNs,ParameterValue="$LAMBDA_ARN" \
1717
--capabilities CAPABILITY_NAMED_IAM

0 commit comments

Comments
 (0)