Skip to content
AWS Lambda Durable Functions

AWS Lambda Durable Functions Skill

Build multi-step Lambda workflows that survive interruption and run for up to a year — the replay model, step operations, wait/callback patterns, saga-style compensation and local testing.

GitHub Docs
Development
Added to Onei AI
Apache-2.0

Install

Install with the skills CLI

One command for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf and dozens of other agents. Needs Node.js; the skill is fetched straight from awslabs/agent-plugins.

$ npx skills add awslabs/agent-plugins --skill aws-lambda-durable-functions

Run it in a terminal. The CLI finds the agents installed on your machine, asks which ones to add the skill to, and whether to install it into the folder you ran it from or for all your projects.

Other ways to install

Copy the whole skill folder — SKILL.md and any scripts or references beside it — into ~/.claude/skills/aws-lambda-durable-functions/, where Claude Code picks it up in every project. Only git is needed.

tmp=$(mktemp -d) && \
  git clone --depth 1 --branch main https://github.com/awslabs/agent-plugins.git "$tmp" && \
  mkdir -p ~/.claude/skills && \
  cp -R "$tmp"/plugins/aws-serverless/skills/aws-lambda-durable-functions ~/.claude/skills/aws-lambda-durable-functions

No scripts or references next to it? Saving the SKILL.md alone as ~/.claude/skills/aws-lambda-durable-functions/SKILL.md works too.

Using another agent? Its personal skills folder
Codex
~/.agents/skills/
Cursor
~/.cursor/skills/
GitHub Copilot
~/.copilot/skills/
Gemini CLI
~/.gemini/skills/
Windsurf
~/.codeium/windsurf/skills/
OpenCode
~/.config/opencode/skills/

About

  • Teaches the replay model first — the source of most durable-function state bugs
  • Covers step operations, wait/callback pauses and saga-pattern compensation
  • Local testing through LocalDurableTestRunner before deployment
  • Validates AWS CLI, runtime and deployment-tool versions before generating code
  • Documents the Python 3.11/3.12 gap where the Durable Execution SDK is not pre-installed
  • Defaults to TypeScript and CDK with documented override phrasing

AWS Lambda durable functions let a single function orchestrate a multi-step process that keeps its progress across interruptions and can execute for up to a year — human-in-the-loop approvals, long AI workflows, saga transactions. The programming model is not obvious, and the thing that catches everyone is replay: the handler is re-executed from the top after each checkpoint, with completed steps returning their recorded results instead of running again. Code that ignores this — a bare Date.now(), a random ID, a non-idempotent side effect outside a step — behaves correctly in testing and corrupts state in production.

This official AWS skill front-loads that model, then covers step operations, wait and callback patterns for pausing on an external event, error handling with the saga pattern for compensating work already done, and testing through LocalDurableTestRunner before anything is deployed.

Prerequisite checking that actually runs

Rather than assuming an environment, the skill validates it first: AWS CLI 2.33.22 or higher with working credentials (aws sts get-caller-identity), Node.js 22+ for TypeScript and JavaScript, or Python 3.11+ — with the real-world caveat that only Lambda runtimes 3.13 and above ship the Durable Execution SDK pre-installed, so Python 3.11 and 3.12 need a container image that brings its own. Deployment needs one of AWS SAM CLI 1.153.1+, AWS CDK v2.237.1+, or direct Lambda deployment access.

Opinionated defaults

TypeScript unless the developer says otherwise, CDK unless they ask for SAM or CloudFormation. Defaults stated up front avoid the agent asking two questions before writing any code, and the override phrasing is documented. Where a requested language or IaC framework has no Durable Execution SDK support, the skill names the gap rather than generating code that cannot work.

Part of the aws-serverless plugin in AWS Labs' official agent plugins repository, Apache-2.0 licensed.

Try it

Once installed, ask your agent something like:

Build me a Lambda durable function for an expense approval flow that waits on a manager's decision and refunds the hold if it's rejected.

SKILL.md

The instructions your agent loads, as published by AWS Labs.

SKILL.md
name
aws-lambda-durable-functions
description
Build 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, workflow orchestration, state machines, retry/checkpoint patterns, long-running stateful Lambda functions, saga pattern, human-in-the-loop callbacks, and reliable serverless applications.

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.

Onboarding
Step 1: Validate Prerequisites

Before using AWS Lambda durable functions, verify:

  1. AWS CLI is installed (2.33.22 or higher) and configured:
   aws --version
   aws sts get-caller-identity
  1. Runtime environment is ready:
  • For TypeScript/JavaScript: Node.js 22+ (node --version)
  • For Python: Python 3.11+ (python --version. Note that currently only Lambda runtime environments 3.13+ come with the Durable Execution SDK pre-installed. 3.11 is the min supported Python version by the Durable SDK itself, however, you could use OCI to bring your own container image with your own Python runtime + Durable SDK.)
  1. Deployment capability exists (one of):
  • AWS SAM CLI (sam --version) 1.153.1 or higher
  • AWS CDK (cdk --version) v2.237.1 or higher
  • Direct Lambda deployment access
Step 2: Select language and IaC framework
Language Selection

Default: TypeScript

Override syntax:

  • "use Python" → Generate Python code
  • "use JavaScript" → Generate JavaScript code

When not specified, ALWAYS use TypeScript

IaC framework selection

Default: CDK

Override syntax:

  • "use CloudFormation" → Generate YAML templates
  • "use SAM" → Generate YAML templates

When not specified, ALWAYS use CDK

Error Scenarios

#### Unsupported Language

  • List detected language
  • State: "Durable Execution SDK is not yet available for [framework]"
  • Suggest supported languages as alternatives

#### Unsupported IaC Framework

  • List detected framework
  • State: "[framework] might not support Lambda durable functions yet"
  • Suggest supported frameworks as alternatives
Serverless MCP Server Unavailable
  • Inform user: "AWS Serverless MCP not responding"
  • Ask: "Proceed without MCP support?"
  • DO NOT continue without user confirmation
Step 3: Install SDK

For TypeScript/JavaScript:

npm install @aws/durable-execution-sdk-js
npm install --save-dev @aws/durable-execution-sdk-js-testing

For Python:

pip install aws-durable-execution-sdk-python
pip install aws-durable-execution-sdk-python-testing
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](references/getting-started.md)
  • Understanding replay model, determinism, or non-deterministic errors -> see [replay-model-rules.md](references/replay-model-rules.md)
  • Creating steps, atomic operations, or retry logic -> see [step-operations.md](references/step-operations.md)
  • Waiting, delays, callbacks, external systems, or polling -> see [wait-operations.md](references/wait-operations.md)
  • Parallel execution, map operations, batch processing, or concurrency -> see [concurrent-operations.md](references/concurrent-operations.md)
  • Error handling, retry strategies, saga pattern, or compensating transactions -> see [error-handling.md](references/error-handling.md)
  • Advanced error handling, timeout handling, circuit breakers, or conditional retries -> see [advanced-error-handling.md](references/advanced-error-handling.md)
  • Testing, local testing, cloud testing, test runner, or flaky tests -> see [testing-patterns.md](references/testing-patterns.md)
  • Deployment, CloudFormation, CDK, SAM, log groups, deploy, or infrastructure -> see [deployment-iac.md](references/deployment-iac.md)
  • Advanced patterns, GenAI agents, completion policies, step semantics, or custom serialization -> see [advanced-patterns.md](references/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](references/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
Critical Rules
  1. All non-deterministic code MUST be in steps (Date.now, Math.random, API calls)
  2. Cannot nest durable operations - use runInChildContext to group operations
  3. Closure mutations are lost on replay - return values from steps
  4. Side effects outside steps repeat - use context.logger (replay-aware)
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:prod 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
MCP Server Configuration

Write access is enabled by default. The plugin ships with --allow-write in .mcp.json, so the MCP server can create projects, generate IaC, and deploy on behalf of the user.

Access to sensitive data (like Lambda and API Gateway logs) is not enabled by default. To grant it, add --allow-sensitive-data-access to .mcp.json.

Resources
Install
Featured

Inngest's durable-execution playbook as an agent skill — steps and memoisation, event and cron triggers, idempotency, cancellation, retries and non-retriable errors.

Seven ways to throttle agent and background workloads — concurrency keys, throttling, rate limiting, debounce, singleton, priority and batching — with a decision guide that picks the right one.

Skill: AWS CDK

by Amazon Web Services

Featured

Official AWS skill for authoring, deploying and debugging CDK stacks — construct patterns, bootstrap, drift, resource import and the CloudFormation errors that trap people.

Browse all skills →