A wrapper for running Temporal workers inside AWS Lambda.
A single run_worker call handles the full per-invocation lifecycle: connecting to the
Temporal server, creating a worker with Lambda-tuned defaults, polling for tasks, and gracefully
shutting down before the invocation deadline.
Quick start:
from temporalio.common import WorkerDeploymentVersion
from temporalio.contrib.aws.lambda_worker import LambdaWorkerConfig, run_worker
def configure(config: LambdaWorkerConfig) -> None:
config.worker_config["task_queue"] = "my-task-queue"
config.worker_config["workflows"] = [MyWorkflow]
config.worker_config["activities"] = [my_activity]
lambda_handler = run_worker(
WorkerDeploymentVersion(
deployment_name="my-service",
build_id="v1.0",
),
configure,
)
Configuration
Client connection settings (address, namespace, TLS, API key) are loaded automatically from a TOML
config file and/or environment variables via temporalio.envconfig. The config file is
resolved in order:
- TEMPORAL_CONFIG_FILE env var, if set.
- temporal.toml in $LAMBDA_TASK_ROOT (typically /var/task).
- temporal.toml in the current working directory.
The file is optional -- if absent, only environment variables are used.
The configure callback receives a LambdaWorkerConfig dataclass with fields pre-populated
with Lambda-appropriate defaults. Override any field directly in the callback. The task_queue
key in worker_config is pre-populated from the TEMPORAL_TASK_QUEUE environment variable if
set.
| Module | otel |
OpenTelemetry helpers for Temporal workers running inside AWS Lambda. |
| Module | _configure |
Configuration for the Lambda worker. |
| Module | _defaults |
Lambda-tuned defaults for Temporal worker and client configuration. |
| Module | _run |
No module docstring; 0/1 variable, 3/4 functions, 1/1 class documented |
From __init__.py:
| Class | |
Passed to the configure callback of run_worker. |
| Function | run |
Create a Temporal worker Lambda handler. |
WorkerDeploymentVersion, configure: Callable[ [ LambdaWorkerConfig], None]) -> Callable[ [ Any, Any], None]:
(source)
ΒΆ
Create a Temporal worker Lambda handler.
Calls the configure callback to collect workflow/activity registrations and option overrides, then returns a Lambda handler function. On each invocation the handler connects to the Temporal server, starts a worker with Lambda-tuned defaults, polls for tasks until the invocation deadline approaches, and then gracefully shuts down.
The version parameter identifies this worker's deployment version. run_worker always enables Worker Deployment Versioning (use_worker_versioning=True). To provide a default versioning behavior for workflows that do not specify one at registration time, set deployment_config in worker_config in the configure callback.
The returned handler has the signature handler(event, context) and should be set as your Lambda function's handler entry point.
Example:
from temporalio.common import WorkerDeploymentVersion
from temporalio.contrib.aws.lambda_worker import (
LambdaWorkerConfig,
run_worker,
)
def configure(config: LambdaWorkerConfig) -> None:
config.worker_config["task_queue"] = "my-task-queue"
config.worker_config["workflows"] = [MyWorkflow]
config.worker_config["activities"] = [my_activity]
lambda_handler = run_worker(
WorkerDeploymentVersion(
deployment_name="my-service",
build_id="v1.0",
),
configure,
)
| Parameters | |
version:WorkerDeploymentVersion | The worker deployment version. Required. |
configure:Callable[ | A callback that receives a LambdaWorkerConfig
(pre-populated with Lambda defaults) and configures workflows,
activities, and options on it. |
| Returns | |
Callable[ | A Lambda handler function. |