Orchestrating Workflows with AWS Step Functions
When a business process has several steps – validate, charge, reserve stock, notify – coding the order, retries and error handling inside one Lambda becomes messy. AWS Step Functions coordinates the steps as a visual state machine and keeps the state of every execution.
stateDiagram-v2
[*] --> ValidateOrder
ValidateOrder --> IsValid
IsValid --> ChargePayment: valid
IsValid --> RejectOrder: invalid
ChargePayment --> Parallel
state Parallel {
ReserveStock
--
SendConfirmation
}
Parallel --> [*]
RejectOrder --> [*]
Amazon States Language (ASL)
{
"StartAt": "ValidateOrder",
"States": {
"ValidateOrder": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke",
"Parameters": { "FunctionName": "validate-order", "Payload.$": "$" },
"Retry": [{ "ErrorEquals": ["Lambda.TooManyRequestsException"], "IntervalSeconds": 2, "MaxAttempts": 3, "BackoffRate": 2 }],
"Catch": [{ "ErrorEquals": ["States.ALL"], "Next": "RejectOrder" }],
"Next": "IsValid" },
"IsValid": { "Type": "Choice",
"Choices": [{ "Variable": "$.Payload.valid", "BooleanEquals": true, "Next": "ChargePayment" }],
"Default": "RejectOrder" },
"ChargePayment": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "End": true },
"RejectOrder": { "Type": "Fail", "Error": "InvalidOrder" }
}
}
| State | Purpose |
|---|---|
| Task | Do work – Lambda, or call 200+ AWS services directly (DynamoDB, SQS, SNS, ECS, Bedrock…) |
| Choice | Branch on input values |
| Parallel | Run branches at the same time |
| Map | Run the same steps for each item of an array (distributed Map for millions of S3 objects) |
| Wait | Pause for seconds or until a timestamp |
| Pass / Succeed / Fail | Shape data, finish successfully or with an error |
Error handling
- Retry with interval, max attempts and exponential backoff per error type.
- Catch routes failures to a compensating step (refund, notify).
- Every execution has a full history – each state’s input, output and errors.
Standard vs Express
| Standard | Express | |
|---|---|---|
| Duration | Up to 1 year | Up to 5 minutes |
| Semantics | Exactly-once | At-least-once |
| Price | Per state transition | Per execution duration and memory |
| Use | Long business processes, human approval | High-volume event processing |
Patterns
- Request/response, run a job (.sync) – wait for ECS/Glue/Batch jobs to finish.
- Wait for callback (.waitForTaskToken) – pause until a human approves via e-mail/app.
- Saga – compensate earlier steps when a later one fails.
- Orchestrate GenAI pipelines: prompt-chain several Bedrock calls with checks between them.
Use Step Functions for orchestration (a defined sequence with retries and state) and EventBridge/SNS for choreography (independent services reacting to events).
Practise it
Virtual lab · Amazon Web Services · 40 min
Orchestrate an order workflow with AWS Step Functions
Write a state machine in the Amazon States Language that validates an order, branches on the amount, charges payment with automatic retries, catches a declined card and ships the order – then trace every execution in the graph and event history.
Quick revision
- A state machine is defined in Amazon States Language (JSON).
- Task, Choice, Parallel, Map, Wait, Pass, Succeed, Fail.
- Retry and Catch give declarative error handling.
- Standard = long and exactly-once; Express = short and high-volume.
- Callback tokens enable human approval steps.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.