PluginBench
Skill
Official
Review
Audit score 70

aws-lambda-durable-functions

aws/agent-toolkit-for-aws

Build resilient multi-step AWS Lambda workflows that run for up to 1 year with automatic state persistence and replay-safe orchestration.

What is aws-lambda-durable-functions?

AWS Lambda durable functions enable long-running, stateful serverless applications that survive interruptions through automatic checkpointing and replay. Use this skill when building multi-step workflows, AI agent orchestration, saga patterns, or any application requiring reliable progress across Lambda invocations.

  • Execute multi-step workflows with automatic state persistence and replay-safe execution
  • Handle long-running operations with wait/callback patterns for external system integration
  • Implement error recovery with saga pattern, compensating transactions, and conditional retry logic
  • Orchestrate parallel execution, map operations, and batch processing with concurrency control
  • Test durable functions locally with LocalDurableTestRunner before cloud deployment
  • Invoke functions with qualified ARNs to enable deterministic replay and execution history tracking

How to install aws-lambda-durable-functions

npx skills add https://github.com/aws/agent-toolkit-for-aws --skill aws-lambda-durable-functions
Prerequisites
  • AWS Lambda function with durable execution enabled at creation time (cannot be retrofitted)
  • AWS credentials configured for CLI access
  • Durable Execution SDK for TypeScript (@aws/durable-execution-sdk-js) or Python (aws_durable_execution_sdk_python)
  • Lambda execution role with AWSLambdaBasicDurableExecutionRolePolicy managed policy attached
  • Qualified function ARN (version, alias, or $LATEST) for invocation
Claude Code
Cursor
Windsurf
Cline

How to use aws-lambda-durable-functions

  1. 1.Create a new Lambda function with durable execution enabled via AWS CLI or IaC tool
  2. 2.Wrap your handler with withDurableExecution (TypeScript) or @durable_execution (Python)
  3. 3.Wrap non-deterministic operations (API calls, database queries, Date.now, Math.random) in context.step() calls
  4. 4.Use context.wait() for delays and context.invoke() for calling other durable functions with qualified ARNs
  5. 5.Implement error handling with try/catch and saga pattern for compensating transactions if needed
  6. 6.Test locally with LocalDurableTestRunner, verifying replay behavior across multiple invocations
  7. 7.Deploy with CloudFormation, CDK, or SAM, ensuring KMS encryption on CloudWatch Log Groups for sensitive data

Use cases

Good for
  • Building AI agent workflows that coordinate multiple steps across Lambda invocations
  • Implementing approval workflows with human-in-the-loop callbacks and external system integration
  • Creating reliable data processing pipelines that checkpoint progress and recover from failures
  • Orchestrating microservice workflows with saga pattern error handling and compensating transactions
  • Processing long-running batch jobs that maintain state across Lambda execution limits
Who it's for
  • Backend engineers building serverless applications requiring multi-step orchestration
  • AI/ML engineers implementing agent workflows with reliable state management
  • DevOps engineers deploying infrastructure-as-code with CloudFormation, CDK, or SAM
  • Solutions architects designing resilient, long-running serverless systems
  • QA engineers testing durable function behavior and replay semantics

aws-lambda-durable-functions FAQ

Can I add durable execution to an existing Lambda function?

No. Durable execution must be enabled at function creation time and cannot be retrofitted. Create a new function with durable execution enabled and migrate your logic into it.

Why do I get errors when invoking my durable function?

Durable functions require qualified ARNs (a specific version, alias, or $LATEST suffix). Unqualified function names will fail. Use aws lambda invoke --function-name my-function:1 or my-function:live, not just my-function.

What code must run inside steps?

All non-deterministic code must run inside steps: Date.now(), Math.random(), UUID generation, API calls, and database queries. Code outside steps will produce different values on replay and corrupt execution state.

Can I call context.step() from inside another step?

No. Durable operations cannot be nested. Use context.runInChildContext() to group operations instead of calling context.step(), context.wait(), or context.invoke() inside a step callback.

How do I handle sensitive data in durable functions?

Do not return secrets, raw credentials, or PII from steps, as step return values are checkpointed and persisted. Enable KMS encryption on associated CloudWatch Log Groups to protect checkpointed data at rest.

Full instructions (SKILL.md)

Source of truth, from aws/agent-toolkit-for-aws.


name: aws-lambda-durable-functions description: Builds resilient, long-running, multi-step applications with AWS Lambda durable functions with automatic state persistence, retry logic, and orchestration for long-running executions. Covers the critical replay model, step operations, wait/callback patterns, error handling with saga pattern, testing with LocalDurableTestRunner. Triggers on phrases like lambda durable functions, durable execution, workflow orchestration, state machines, retry/checkpoint patterns, long-running stateful Lambda functions, saga pattern, human-in-the-loop callbacks, reliable serverless applications, context.step, context.wait, context.invoke, context.runInChildContext, withDurableExecution, DurableContext, UnrecoverableInvocationError, durable-execution-sdk, qualified ARN invocation, and durable handler replay. version: 1

AWS 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.

  1. 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.
  2. Durable functions must be invoked with a qualified ARN — a specific version, an alias, or the literal $LATEST suffix. An unqualified function name will fail. See the Invocation Requirements section below for examples.
  3. Durable operations cannot be nested. You cannot call context.step(), context.wait(), or context.invoke() from inside another step's callback. Use context.runInChildContext() to group operations instead.
  4. 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.
  5. Closure mutations are lost on replay - return values from steps
  6. 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_step decorator + context.step(my_step(args)), or inline context.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 DurableFunctionTestRunner class directly - instantiate with handler, use context manager, call run(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 state
  • lambda:GetDurableExecutionState - Retrieve execution state
  • CloudWatch Logs permissions

Additional permissions needed for:

  • Durable invokes: lambda:InvokeFunction on target function ARNs
  • External callbacks: Systems need lambda:SendDurableExecutionCallbackSuccess and lambda:SendDurableExecutionCallbackFailure

Validation Guidelines

When writing or reviewing durable function code, ALWAYS check for these replay model violations:

  1. Non-deterministic code outside steps: Date.now(), Math.random(), UUID generation, API calls, database queries must all be inside steps
  2. Nested durable operations in step functions: Cannot call context.step(), context.wait(), or context.invoke() inside a step function — use context.runInChildContext() instead
  3. Closure mutations that won't persist: Variables mutated inside steps are NOT preserved across replays — return values from steps instead
  4. Side effects outside steps that repeat on replay: Use context.logger for logging (it is replay-aware and deduplicates automatically)

When implementing or modifying tests for durable functions, ALWAYS verify:

  1. All operations have descriptive names
  2. Tests get operations by NAME, never by index
  3. Replay behavior is tested with multiple invocations
  4. Use LocalDurableTestRunner for 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 waitForCallback originates from external systems — validate and sanitize before processing.
  • Logging: Avoid DEBUG log level in non-development environments as it may expose step results and execution state. Enable CloudWatch Logs encryption with KMS.

Resources