Build multi-step applications and AI workflows with AWS Lambda durable functions | AWS News Blog (opens in new tab)
AWS Lambda durable functions introduce a simplified way to manage complex, long-running workflows directly within the standard Lambda experience. By utilizing a checkpoint and replay mechanism, developers can now write sequential code for multi-step processes that automatically handle state management and retries without the need for external orchestration services. This feature significantly reduces the cost of long-running tasks by allowing functions to suspend execution for up to one year without incurring compute charges during idle periods.
Durable Execution Mechanism
- The system uses a "durable execution" model based on checkpointing and replay to maintain state across function restarts.
- When a function is interrupted or resumes from a pause, Lambda re-executes the handler from the beginning but skips already-completed operations by referencing saved checkpoints.
- This architecture ensures that business logic remains resilient to failures and can survive execution environment recycles.
- The execution state can be maintained for extended periods, supporting workflows that require human intervention or long-duration external processes.
Programming Primitives and SDK
- The feature requires the inclusion of a new open-source durable execution SDK in the function code.
- Steps: The
context.step()method defines specific blocks of logic that the system checkpoints and automatically retries upon failure. - Wait: The
context.wait()primitive allows the function to terminate and release compute resources while waiting for a specified duration, resuming only when the time elapses. - Callbacks: Developers can use
create_callback()to pause execution until an external event, such as an API response or a manual approval, is received. - Advanced Control: The SDK includes
wait_for_condition()for polling external statuses andparallel()ormap()operations for managing concurrent execution paths.
Configuration and Setup
- Durable execution must be enabled at the time of the Lambda function's creation; it cannot be retroactively enabled for existing functions.
- Once enabled, the function maintains the same event handler structure and service integrations as a standard Lambda function.
- The environment is specifically optimized for high-reliability use cases like payment processing, AI agent orchestration, and complex order management.
AWS Lambda durable functions represent a major shift for developers who need the power of stateful orchestration but prefer to keep their logic within a single code-based environment. It is highly recommended for building AI workflows and multi-step business processes where state persistence and cost-efficiency are critical requirements.