
AWS Lambda Durable Functions
OfficialFreeBuild resilient, long-running applications with AWS Lambda.
Free · Opens the source repo
What AWS Lambda Durable Functions does
AWS Lambda Durable Functions enables developers to create robust, multi-step applications that can run for extended periods, up to one year, while ensuring reliable execution despite interruptions. This skill is particularly useful for those building serverless applications that require orchestration and state management, allowing for automatic state persistence and retry logic. By leveraging durable functions, developers can implement complex workflows that involve multiple steps and interactions with external systems, all while maintaining the integrity of the execution state.
The skill is designed to work seamlessly with AWS services, primarily utilizing the AWS MCP server, though it can also function in any environment with properly configured AWS credentials. It provides a structured approach to managing long-running processes, including critical features such as the replay model, step operations, and error handling strategies. For instance, the skill includes guidelines for implementing the saga pattern for error recovery, ensuring that applications can gracefully handle failures and continue processing as needed.
Users can benefit from a comprehensive set of reference materials that cover various aspects of durable functions, including getting started guides, advanced error handling techniques, and testing patterns. These resources are essential for developers looking to deepen their understanding of durable execution and how to implement it effectively in their applications. The skill supports both TypeScript and Python, making it accessible to a wide range of developers with different programming backgrounds.
In summary, AWS Lambda Durable Functions is an essential tool for developers aiming to build reliable and scalable serverless applications that require complex workflows and state management. By following the provided guidelines and utilizing the reference materials, users can effectively implement durable functions in their projects, ensuring robust and resilient application behavior.
When to use it
Use this skill when developing serverless applications that require multi-step workflows, state management, and robust error handling.
When not to use it
This skill may not be suitable for simple, short-lived functions that do not require orchestration or state persistence.
What you can build with it
Building a Complex Workflow
Use this skill to orchestrate a multi-step application that requires state management and can handle long-running processes.
Implementing Retry Logic
Leverage the built-in retry strategies to ensure your application can recover from transient errors without losing state.
Testing Durable Functions Locally
Utilize the LocalDurableTestRunner to test your durable functions locally before deploying them to AWS.
How to install AWS Lambda Durable Functions
View source1. Install with the skills CLI
npx skills add aws/agent-toolkit-for-aws/aws-lambda-durable-functions --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by awsAWS Lambda durable functions
Build resilient multi-step applications and AI workflows that can execute for up to 1 year while maintaining reliable progress despite interruptions.
Works best with the AWS MCP server but is not required. All AWS interactions in this skill use standard AWS CLI commands that work in any environment with configured AWS credentials.
Critical Rules
Read these before writing any code. Each one is a constraint that will silently break a function if violated.
- Durable execution must be enabled at function creation time — it cannot be retrofitted. A new Lambda function must be created with durable execution turned on. Migrate the logic into the new function; do not attempt to install the SDK and wrap the handler of the existing function and expect it to work.
- Durable functions must be invoked with a qualified ARN — a specific version, an alias, or the literal
$LATESTsuffix. An unqualified function name will fail. See the Invocation Requirements section below for examples. - Durable operations cannot be nested. You cannot call
context.step(),context.wait(), orcontext.invoke()from inside another step's callback. Usecontext.runInChildContext()to group operations instead. - All non-deterministic code must run inside steps.
Date.now(),Math.random(), UUID generation, API calls, and database queries outside a step will produce different values on replay and corrupt execution state. - Closure mutations are lost on replay - return values from steps
- Side effects outside steps repeat - use
context.logger(replay-aware)
When to Load Reference Files
Load the appropriate reference file based on what the user is working on:
- Getting started, basic setup, example, ESLint, or Jest setup -> see getting-started.md
- Understanding replay model, determinism, or non-deterministic errors -> see replay-model-rules.md
- Creating steps, atomic operations, or retry logic -> see step-operations.md
- Waiting, delays, callbacks, external systems, or polling -> see wait-operations.md
- Parallel execution, map operations, batch processing, or concurrency -> see concurrent-operations.md
- Error handling, retry strategies, saga pattern, or compensating transactions -> see error-handling.md
- Advanced error handling, timeout handling, circuit breakers, or conditional retries -> see advanced-error-handling.md
- Testing, local testing, cloud testing, test runner, or flaky tests -> see testing-patterns.md
- Deployment, CloudFormation, CDK, SAM, log groups, deploy, or infrastructure -> see deployment-iac.md
- Advanced patterns, GenAI agents, completion policies, step semantics, or custom serialization -> see advanced-patterns.md
- troubleshooting, stuck execution, failed execution, debug execution ID, execution history, execution error, why did my execution fail, execution timed out, callback not received, diagnose execution, or root cause execution -> see troubleshooting-executions.md
Quick Reference
Basic Handler Pattern
TypeScript:
import { withDurableExecution, DurableContext } from '@aws/durable-execution-sdk-js';
export const handler = withDurableExecution(async (event, context: DurableContext) => {
const result = await context.step('process', async () => processData(event));
return result;
});
Python:
from aws_durable_execution_sdk_python import durable_execution, DurableContext
@durable_execution
def handler(event: dict, context: DurableContext) -> dict:
result = context.step(lambda _: process_data(event), name='process')
return result
Python API Differences
The Python SDK differs from TypeScript in several key areas:
- Steps: Use
@durable_stepdecorator +context.step(my_step(args)), or inlinecontext.step(lambda _: ..., name='...'). Prefer the decorator for automatic step naming. - Wait:
context.wait(duration=Duration.from_seconds(n), name='...') - Exceptions:
ExecutionError(permanent),InvocationError(transient),CallbackError(callback failures) - Testing: Use
DurableFunctionTestRunnerclass directly - instantiate with handler, use context manager, callrun(input=...)
Invocation Requirements
Durable functions require qualified ARNs (version, alias, or $LATEST):
# Valid
aws lambda invoke --function-name my-function:1 output.json
aws lambda invoke --function-name my-function:live output.json
# Invalid - will fail
aws lambda invoke --function-name my-function output.json
IAM Permissions
Your Lambda execution role MUST have the AWSLambdaBasicDurableExecutionRolePolicy managed policy attached. This includes:
lambda:CheckpointDurableExecution- Persist execution statelambda:GetDurableExecutionState- Retrieve execution state- CloudWatch Logs permissions
Additional permissions needed for:
- Durable invokes:
lambda:InvokeFunctionon target function ARNs - External callbacks: Systems need
lambda:SendDurableExecutionCallbackSuccessandlambda:SendDurableExecutionCallbackFailure
Validation Guidelines
When writing or reviewing durable function code, ALWAYS check for these replay model violations:
- Non-deterministic code outside steps:
Date.now(),Math.random(), UUID generation, API calls, database queries must all be inside steps - Nested durable operations in step functions: Cannot call
context.step(),context.wait(), orcontext.invoke()inside a step function — usecontext.runInChildContext()instead - Closure mutations that won't persist: Variables mutated inside steps are NOT preserved across replays — return values from steps instead
- Side effects outside steps that repeat on replay: Use
context.loggerfor logging (it is replay-aware and deduplicates automatically)
When implementing or modifying tests for durable functions, ALWAYS verify:
- All operations have descriptive names
- Tests get operations by NAME, never by index
- Replay behavior is tested with multiple invocations
- Use
LocalDurableTestRunnerfor local testing
Security Considerations
- Checkpoint data encryption: Execution state is persisted automatically. Enable KMS encryption on associated CloudWatch Log Groups to protect checkpointed data at rest.
- Sensitive data in step results: Step return values are checkpointed and persisted. Do not return secrets, raw credentials, or PII from steps — store sensitive data in Secrets Manager or SSM Parameter Store and return references instead.
- Input validation: Validate and sanitize event payloads at the handler entry point before passing data to steps.
- Credential management: Retrieve secrets from AWS Secrets Manager or SSM Parameter Store within steps.
- Callback payload validation: Data received via
waitForCallbackoriginates from external systems — validate and sanitize before processing. - Logging: Avoid
DEBUGlog level in non-development environments as it may expose step results and execution state. Enable CloudWatch Logs encryption with KMS.
Resources
Frequently asked questions about AWS Lambda Durable Functions
Similar skills
Python PyPI Package Builder
Streamline the process of creating and publishing Python packages.
Minecraft Plugin Development
Streamline your Minecraft server plugin creation.
MCP Server Builder
Easily build .NET MCP servers with the latest standards.
CommunityToolkit.Mvvm Messenger
Decoupled communication for ViewModels in .NET applications.
MVVM Toolkit DI
Streamline ViewModel integration with Dependency Injection in .NET.
MCP Apps Builder
Essential guidelines for MCP server development.
