Orchestrating Workflows with Step Functions
Coordinate multi-step processes with Step Functions state machines, including retries, error handling, parallel steps and human approval.
Advanced · about 4 hours · difficulty 3/5
Learn first: Decoupling with SQS, SNS and EventBridge
When a business process has many steps (validate order, charge payment, reserve stock, send email) chaining Lambdas together by hand gets messy. AWS Step Functions lets you define the flow as a state machine with built-in retries and error handling. Azure Logic Apps / Durable Functions and Google Workflows are the equivalents.
Core ideas
- Workflows are written in Amazon States Language (JSON) or drawn in Workflow Studio.
- State types: Task (do work), Choice (branch), Parallel, Map (loop over items), Wait, Succeed and Fail.
- Retry and Catch blocks handle errors declaratively.
- Direct SDK integrations call over 200 AWS services without a Lambda in between.
Standard vs Express
- Standard workflows: up to a year long, exactly-once execution, full visual history. Good for business processes.
- Express workflows: high-volume, short (up to 5 minutes), cheaper. Good for event processing.
Patterns
- Saga pattern: compensating steps that undo earlier work when a later step fails (refund the payment if stock is unavailable).
- Wait for callback with task tokens for human approval or external systems.
- Distributed Map to process millions of S3 objects in parallel.
Pitfalls
- Putting huge payloads in state (256 KB limit); pass S3 references instead.
- Using Step Functions for a simple two-step chain where one Lambda or an SQS queue is enough.
You are ready to move on when you can build a workflow with a choice, a retry policy and a compensating step, and read its execution history to debug a failure.
Key concepts
- Amazon States Language
- Task, Choice, Parallel, Map states
- Retry and Catch
- Standard vs Express workflows
- Direct SDK integrations
- Saga pattern
- Callback with task tokens
Mini project
Model a food-order workflow in Step Functions: validate order, charge payment (a Lambda that randomly fails), retry twice, and on final failure run a refund step and send an SNS notification. A few dozen executions stay within free tier; delete the state machine and functions after.
Check yourself
When would you choose Step Functions over chaining Lambda functions with SQS queues?