Skip to content

AWS Step Functions and Lambda Durable Functions

durable-execution-sdk-js 3.0

A workflow that waits hours for a person or retries a flaky API cannot live in one function invocation, so something must remember where it stopped. Step Functions remembers from outside your code: you declare states in JSON, and the service runs them and records every transition. Lambda durable functions remember from inside your code: the SDK checkpoints each step, and on resume your handler runs again from the top while completed steps return their saved results.

StateDoes
TaskCalls Lambda or an AWS API
ChoiceBranches on input
WaitPauses for a time or until a timestamp
Parallel / MapRuns branches or items concurrently
Pass, Succeed, FailShape data, or end

A state machine is Amazon States Language (ASL): a StartAt name and a States map where each state names its Next or sets End. Set QueryLanguage to JSONata for new machines; if omitted it defaults to JSONPath.

{
"QueryLanguage": "JSONata",
"StartAt": "Charge",
"States": {
"Charge": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Arguments": { "FunctionName": "charge",
"Payload": "{% $states.input %}" },
"Output": "{% $states.result.Payload %}",
"End": true
}
}
}
PropertyStandardExpress
Max duration1 year5 minutes
SemanticsExactly-onceAt-least-once (async)
History25,000 events, kept 90 daysCloudWatch Logs only
BillingPer state transitionPer request plus duration

Standard suits long, auditable business processes; Express suits high-volume, short event processing. The type is fixed at creation. Synchronous Express executions are at-most-once.

Terminal window
aws stepfunctions create-state-machine \
--name ingest --type EXPRESS \
--definition file://ingest.asl.json \
--role-arn "$SFN_ROLE"

Gotcha: A Standard execution fails when its history reaches 25,000 events. A long loop of small states hits that limit; move the loop into a child execution or a Distributed Map.

Field (JSONata)Purpose
ArgumentsInput to the task
OutputWhat the state passes on
AssignStore variables for later states
$states.input / .resultReserved variables

JSONata replaces JSONPath’s five fields (InputPath, Parameters, ResultSelector, ResultPath, OutputPath) with two. Variables set with Assign let later states read earlier results without threading them through every output.

"Lookup": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Arguments": { "FunctionName": "lookup" },
"Assign": {
"customer": "{% $states.result.Payload %}"
},
"Next": "Notify"
}

Gotcha: Input and output for every state, task and execution are capped at 256 KiB, and exceeding it fails with States.DataLimitExceeded. Store large data in S3 and pass the key.

Retry fieldDefault
IntervalSeconds1
MaxAttempts3 (0 = never retry)
BackoffRate2.0
MaxDelaySecondsNo cap
JitterStrategyNONE (or FULL)

Retry re-runs the failed state; Catch moves to a fallback state when retries run out. Both match on ErrorEquals, checked in order. States.ALL matches any error and must come last.

"Retry": [{
"ErrorEquals": [
"Lambda.TooManyRequestsException"],
"IntervalSeconds": 2, "MaxAttempts": 6,
"BackoffRate": 2, "JitterStrategy": "FULL"
}],
"Catch": [{
"ErrorEquals": ["States.ALL"],
"Next": "Refund"
}]

Gotcha: ASL sets no useful task timeout by default (TimeoutSeconds defaults to 99,999,999), so a worker that never answers leaves the execution stuck. Set a timeout, plus HeartbeatSeconds on callback tasks.

PatternResource suffixWaits for
Request ResponsenoneThe HTTP response
Run a job.syncJob completion (Standard only)
Wait for callback.waitForTaskTokenSendTaskSuccess
AWS SDKaws-sdk:<service>:<action>Any API action

Optimized integrations such as lambda:invoke or sqs:sendMessage call services without a Lambda in between; SDK integrations reach over 200 more services. A callback task hands its token to an external system and pauses until that system calls SendTaskSuccess or SendTaskFailure.

"Approve": {
"Type": "Task",
"Resource":
"arn:aws:states:::lambda:invoke.waitForTaskToken",
"HeartbeatSeconds": 3600,
"Arguments": { "FunctionName": "ask-approver",
"Payload": {
"token": "{% $states.context.Task.Token %}"
} },
"Next": "Ship"
}
ModeInputConcurrency
InlineJSON array in state inputLimited beyond ~40 items
DistributedArray or S3 objects (CSV, JSON, Parquet)Up to 10,000 child executions

Distributed mode runs each item, or batch of items, as a child execution, so one map can process millions of objects without hitting the parent’s history or payload limits. Write results to S3 with ResultWriter when they exceed 256 KiB.

"Each": {
"Type": "Map", "MaxConcurrency": 500,
"ItemReader": {
"Resource": "arn:aws:states:::s3:listObjectsV2",
"Arguments": { "Bucket": "in", "Prefix": "d/" }
},
"ItemProcessor": {
"ProcessorConfig": { "Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS" },
"StartAt": "Work", "States": { "Work": {
"Type": "Pass", "End": true } }
},
"End": true
}

Tip: Set MaxConcurrency to what the downstream service tolerates. 10,000 parallel Lambda calls will throttle an account with the default concurrency limit.

DurableContext methodDoes
step(name, fn)Runs fn once, checkpoints the result
wait(duration)Suspends with no compute charge
invoke(name, fnArn, input)Calls another function durably
map / parallelConcurrent durable work
runInChildContextGroups several operations

Wrap the handler with withDurableExecution. Managed runtimes support Node.js (22, 24), Python (3.13, 3.14), Java (17, 21, 25) and .NET (8, 10). Node.js and Python runtimes include the SDK, while Java and .NET need it bundled; bundling is recommended everywhere for production.

import { withDurableExecution }
from "@aws/durable-execution-sdk-js";
export const handler = withDurableExecution(
async (event, ctx) => {
const hold = await ctx.step("reserve",
async () => reserve(event.orderId));
await ctx.wait({ hours: 24 });
return ctx.step("charge",
async () => charge(hold));
});

Gotcha: On every resume the handler re-runs from the top. Code outside step() runs again, so Date.now(), random IDs and API calls there produce different values on replay. Put them inside a step.

SettingValue
ExecutionTimeoutRequired, 1–31,622,400 s (366 days)
RetentionPeriodInDays1–90, default 14
Operations per execution30,000
Payload per operation1 MB

Durable execution is enabled only at function creation, via --durable-config, and cannot run on an unqualified function name. createCallback or waitForCallback returns a callback ID; an external system completes it with SendDurableExecutionCallbackSuccess, Failure or Heartbeat.

{
"Effect": "Allow",
"Action": [
"lambda:SendDurableExecutionCallbackSuccess",
"lambda:SendDurableExecutionCallbackFailure",
"lambda:SendDurableExecutionCallbackHeartbeat"
],
"Resource":
"arn:aws:lambda:eu-west-1:1234:function:f:*"
}

Warning: Invoking through $LATEST means a deploy mid-execution replays checkpoints against different code. Use $LATEST only for prototyping; invoke a published version or an alias that points to one.

NeedChoose
Visual, auditable, mostly AWS API callsStep Functions Standard
Very high volume, under 5 minutesStep Functions Express
Logic best written as code, one teamLambda durable functions
Fan out over millions of S3 objectsDistributed Map

Step Functions Standard bills per state transition; Express bills per request plus GB-seconds. Durable functions add charges for durable operations, data written, and retention to normal Lambda compute, and waits incur no duration charge. Prices below are us-east-1 list prices on the verification date.

Standard $0.025 per 1,000 transitions
(4,000 free per month)
Express $1.00 per 1M requests + duration
Durable $8.00 per 1M operations
+ $0.25 per GB written + retention