Step Functions
Orchestrating work with AWS Step Functions: states, JSONata, retries and catches, service integrations, callbacks and workflow types.
Policy documents and evaluation logicDynamoDB tables, keys and queriesLambda concurrency, cold starts and failures
Step Functions
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A state machine holds the order of steps, retries and waiting, so your functions don't have to.
- Task states call AWS services directly; Choice, Wait, Parallel and Map control the flow without code.
- Declare Retry with backoff for transient errors and Catch for business failures, and plan how to undo completed steps.
- Standard workflows run up to a year with exactly-once execution and are billed per state transition. Express run up to five minutes and suit high volume.
- The callback pattern pauses a task until something outside sends back its token.
- State input and output are limited to 256 KiB, so pass references to large data.
The glue code problem
An order needs stock reserved, payment taken, a human check for large amounts and a shipment booked. Write that as one function calling the others and you’ve built a fragile thing: it pays to sit waiting, it dies at its timeout, and after a crash nobody knows which steps ran. Chain functions through queues and the process exists only in your head.
AWS Step Functions makes the process itself a managed object. You describe a state machine, and the service runs it, records every step, retries and waits. It’s a checklist held by a foreman rather than by whichever worker happens to be on shift.
States
A definition is JSON in the Amazon States Language. Here’s a trimmed order flow using JSONata, the newer expression language that AWS recommends over the older JSONPath fields:
{
"QueryLanguage": "JSONata",
"StartAt": "Reserve",
"States": {
"Reserve": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:updateItem",
"Arguments": {
"TableName": "stock",
"Key": {"sku": {"S": "{% $states.input.sku %}"}},
"UpdateExpression": "SET qty = qty - :one",
"ConditionExpression": "qty >= :one",
"ExpressionAttributeValues": {":one": {"N": "1"}}
},
"Output": "{% $states.input %}",
"Catch": [{"ErrorEquals": ["DynamoDB.ConditionalCheckFailedException"],
"Next": "OutOfStock"}],
"Next": "BigOrder"
},
"BigOrder": {
"Type": "Choice",
"Choices": [{"Condition": "{% $states.input.total > 1000 %}",
"Next": "Review"}],
"Default": "Done"
},
"Review": {"Type": "Pass", "Next": "Done"},
"Done": {"Type": "Succeed"},
"OutOfStock": {"Type": "Fail", "Error": "OutOfStock"}
}
}
The first step needs no Lambda at all. Step Functions calls DynamoDB directly with a conditional write. Task does work; Choice, Wait, Parallel, Map, Pass, Succeed and Fail shape the flow. The state machine has its own IAM role, which needs permission for every call it makes.
Errors and compensation
A Retry block names errors and says how to try again. By default the first retry waits 1 second, the delay doubles and there are 3 attempts, so waits of 1, 2 and 4 seconds. Cap the delay and add jitter for shared dependencies. Catch routes a failure to another state.
Retries mean a step can run more than once, so make side effects idempotent. There’s no rollback across services. If payment succeeded and shipping fails, you write the refund step yourself: this is the saga pattern.
Two habits keep this manageable. First, separate kinds of failure. A throttled API or a network blip deserves a retry. “Card declined” doesn’t: retrying won’t change the answer, so catch it and take the business path. Give your own errors distinct names so the definition can tell them apart. Second, decide what happens at the end of the line. An unhandled error fails the whole execution, so add a catch-all route that records what failed and alerts someone, and alarm on failed executions.
States.ALL matches most errors but not all of them. Exceeding the payload limit, for one, has to be named explicitly, and some runtime errors can’t be caught.
Waiting
A task can request and respond at once, run a job and wait for it to finish (.sync), or hand out a task token and pause until someone returns it (.waitForTaskToken). That last one covers human approvals and slow external systems with nothing running in between. Set timeouts, or a lost token leaves an execution waiting a very long time.
Map runs the same steps over a list. Distributed Map runs each item or batch as a child execution, for very large sets such as the objects in a bucket.
Standard or Express
| Standard | Express | |
|---|---|---|
| Longest run | one year | five minutes |
| Execution | exactly once | at least once (async), at most once (sync) |
| Billing | per state transition | executions, duration, memory |
| History | kept for 90 days | in CloudWatch Logs if enabled |
.sync and callbacks |
yes | no |
A Standard execution history is capped at 25,000 events, so long loops need child or new executions.
Use a workflow when steps need visibility, waiting or compensation. Don’t use one to wrap a single function. For orchestration written as ordinary code inside Lambda, look at Lambda durable functions, which checkpoint progress and can run for up to a year. For loose reactions with no central owner, use events.
Calling and changing it
Something has to start an execution: an API, an EventBridge rule, a schedule or your own code with StartExecution. Give Standard executions a meaningful, unique name, such as the order ID. Starting the same name twice while one is running with different input is refused, which is a cheap guard against duplicate orders.
Treat the definition as code. Keep it in your repository, deploy it with CloudFormation, CDK or SAM, and publish versions and aliases so a change can be released gradually while running executions finish on the definition they started with. Enable logging and tracing, especially for Express, where there’s no built-in history to inspect afterwards.
Watch cost shape as well. A Standard workflow that loops to poll something every few seconds pays for each transition of the loop. A callback or a .sync integration usually does the same waiting for far fewer transitions.
About the video
The embed is a clip from AWS’s re:Invent 2025 session on production-grade workflow patterns (API313), 3:26 to 28:18. Its chapters there cover benefits, workflow capabilities, data and scaling patterns and cost models. It’s a vendor talk that assumes you’ve seen a state machine. I judged it from chapters and description; there’s no audio-language flag, though title and captions are English.
What was run: the definition passed cfn-lint 1.41.0 inside a template. The same linter also passed copies whose Next or Default named a state that didn’t exist, though it caught a misspelled state type, so a clean lint isn’t validation. Use the service’s validate and test-state APIs. moto couldn’t execute the machine reliably, so it hasn’t run. Behaviour and quotas come from the Step Functions developer guide, checked in November 2026.
Check yourself
Payment succeeds and shipping then fails. Does Step Functions roll the payment back?
No. It has no transaction across services. You add a Catch that leads to a compensating step, such as a refund, and make that step safe to retry.
You need an approval that may take three days. Which workflow type and pattern?
A Standard workflow using waitForTaskToken. Express workflows end within five minutes and don't support callbacks.
A high-volume event handler runs a two-second workflow thousands of times a second. Which type is likely cheaper, and what must its steps be?
Express, billed by requests and duration. Asynchronous Express is at-least-once, so the steps must be idempotent.
A task output is 2 MB and the execution fails. What do you change?
Write the data to S3 or a database and pass the key between states, since payloads are capped at 256 KiB.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.