Difficulty: Advanced
What is AWS Step Functions, and when would you use it instead of chaining Lambda functions directly?
AWS Step Functions is a serverless orchestration service that runs workflows defined as state machines, coordinating Lambda functions and more than 200 AWS services with built-in retries, error handling, branching, parallelism and waiting. You use it when a business process has several steps and you want its state, failures and history managed for you instead of hand-wiring Lambdas that call each other.
Workflows are written in Amazon States Language (ASL), a JSON document, or built visually in Workflow Studio. The main state types are:
Each Task can declare Retry (with backoff) and Catch (route errors to a fallback state). Since late 2024, workflows can use JSONata expressions and variables, which removes much of the old InputPath/ResultPath juggling.
| Standard | Express | |
|---|---|---|
| Max duration | Up to 1 year | Up to 5 minutes |
| Execution semantics | Exactly-once | At-least-once (async) or at-most-once (sync) |
| Pricing | Per state transition | Per request and duration |
| History | Visual history kept in the console | Sent to CloudWatch Logs |
| Good for | Order processing, approvals, long ETL | High-volume event processing, IoT, API backends |
.sync): start a Glue job, ECS task or another state machine and wait for it to finish..waitForTaskToken): pause until an external system returns a task token, ideal for human approval or a third-party webhook.If Lambda A calls Lambda B directly, you pay for A while it waits, you have to write your own retry and timeout logic, and when step 3 of 5 fails you have no clear record of what happened. Step Functions gives you:
A classic example is a saga for a food order: reserve inventory, charge the customer through a payment gateway, assign a delivery partner. If assignment fails, Catch routes to compensating steps that refund the payment and release the inventory.
{
"StartAt": "ChargePayment",
"States": {
"ChargePayment": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": { "FunctionName": "charge-payment", "Payload.quot;: "quot; },
"Retry": [{
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 2, "MaxAttempts": 3, "BackoffRate": 2
}],
"Catch": [{ "ErrorEquals": ["States.ALL"], "Next": "ReleaseInventory" }],
"Next": "Done"
},
"ReleaseInventory": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:deleteItem",
"Parameters": {
"TableName": "reservations",
"Key": { "orderId": { "S.quot;: "$.orderId" } }
},
"Next": "OrderFailed"
},
"OrderFailed": { "Type": "Fail", "Error": "PaymentFailed" },
"Done": { "Type": "Succeed" }
}
}
The payment task retries with exponential backoff (2s, 4s, 8s); if it still fails, a direct DynamoDB integration releases the reservation without needing another Lambda.
State Machines, Amazon States Language, Standard vs Express, Saga Pattern, Service Integrations, Retry and Catch