Step Functions: Orchestrating Serverless Workflows
Define multi-step workflows as state machines in Step Functions, handle errors with catch and retry blocks, and integrate native SDK integrations.
Step Functions: Orchestrating Serverless Workflows is a free AWS Solutions Architect lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Are AWS Step Functions?
AWS Step Functions is a fully managed workflow orchestration service that coordinates distributed applications as a series of steps defined in a state machine. Each step in the state machine is a state — a Lambda invocation, an AWS SDK call, a wait period, a parallel branch, or a choice (if/else). Step Functions manages state, handles retries, and provides a visual execution history, eliminating the need to write orchestration logic in application code.
Amazon States Language (ASL)
State machines are defined in Amazon States Language (ASL), a JSON-based language. Each state has a Type (Task, Choice, Wait, Parallel, Map, Pass, Succeed, Fail) and transitions to a Next state or ends. The Resource field of a Task state specifies the AWS service to invoke — an ARN for Lambda, or an optimised service integration ARN for over 200 AWS services without an intermediate Lambda.
{
'Comment': 'Order processing workflow',
'StartAt': 'ValidateOrder',
'States': {
'ValidateOrder': {
'Type': 'Task',
'Resource': 'arn:aws:lambda:us-east-1:123456789012:function:ValidateOrder',
'Next': 'ChargePayment',
'Retry': [{'ErrorEquals': ['Lambda.ServiceException'], 'IntervalSeconds': 2, 'MaxAttempts': 3}]
},
'ChargePayment': {
'Type': 'Task',
'Resource': 'arn:aws:states:::dynamodb:putItem',
'Parameters': {'TableName': 'Orders', 'Item': {'orderId': {'S.$': '$.orderId'}}},
'End': true
}
}
}Standard vs Express Workflows
Step Functions has two workflow types. Standard Workflows: durable, up to 1 year duration, exactly-once execution semantics, full execution history stored for 90 days — suitable for long-running business processes. Express Workflows: high-throughput (over 100,000 executions per second), up to 5 minutes duration, at-least-once semantics, logs sent to CloudWatch — suitable for real-time event processing and IoT data pipelines. Choose based on duration, throughput, and idempotency requirements.
# Create a Standard workflow state machine
aws stepfunctions create-state-machine \
--name OrderProcessing \
--definition file://order-state-machine.json \
--role-arn arn:aws:iam::123456789012:role/StepFunctionsRole \
--type STANDARD
# Create an Express workflow for high-throughput
aws stepfunctions create-state-machine \
--name ClickstreamProcess \
--definition file://click-state-machine.json \
--role-arn arn:aws:iam::123456789012:role/StepFunctionsRole \
--type EXPRESSTask States and Service Integrations
Step Functions Task states support two integration patterns. Request-Response: call an AWS service and proceed immediately (fire-and-forget). Sync Integration: call a service and wait for it to complete before moving to the next state (e.g., wait for an ECS task to finish, a Glue job to complete, or a SageMaker training job to end). Sync integration uses the :sync:2 suffix on the resource ARN and eliminates the need for polling logic.
# Sync integration: start Glue job and wait for completion
'RunGlueETL': {
'Type': 'Task',
'Resource': 'arn:aws:states:::glue:startJobRun.sync:2',
'Parameters': {
'JobName': 'clean-sales'
},
'Next': 'RunAthenaQuery'
}Choice States for Branching Logic
A Choice state implements conditional branching — the workflow equivalent of an if/else or switch statement. You define Choices as an array of conditions; the first matching condition determines the next state. A Default state handles unmatched cases. Choice states allow you to route an order to different fulfilment paths based on product type, customer tier, or payment status, without writing conditional Lambda logic.
'RouteByOrderType': {
'Type': 'Choice',
'Choices': [
{
'Variable': '$.orderType',
'StringEquals': 'DIGITAL',
'Next': 'FulfillDigital'
},
{
'Variable': '$.orderType',
'StringEquals': 'PHYSICAL',
'Next': 'FulfillPhysical'
}
],
'Default': 'HandleUnknownType'
}Parallel and Map States
A Parallel state runs multiple branches simultaneously and waits for all to complete before proceeding — useful for concurrent tasks like running a credit check and inventory check at the same time. A Map state iterates over an array in the input and applies the same set of states to each element in parallel — useful for processing a batch of items returned by a previous step, such as resizing multiple uploaded images.
'ProcessImages': {
'Type': 'Map',
'ItemsPath': '$.imageKeys',
'MaxConcurrency': 10,
'Iterator': {
'StartAt': 'ResizeImage',
'States': {
'ResizeImage': {
'Type': 'Task',
'Resource': 'arn:aws:lambda:us-east-1:123:function:ResizeImage',
'End': true
}
}
},
'Next': 'NotifyComplete'
}Error Handling: Catch and Retry
Every Task state in Step Functions can have Retry and Catch blocks for resilient error handling. Retry specifies which error types trigger automatic retries with configurable IntervalSeconds, MaxAttempts, and BackoffRate (exponential backoff multiplier). Catch specifies fallback states for unrecoverable errors. This declarative error handling avoids repetitive try/catch blocks inside Lambda functions.
'ChargeCard': {
'Type': 'Task',
'Resource': 'arn:aws:lambda:us-east-1:123:function:ChargeCard',
'Retry': [{
'ErrorEquals': ['Lambda.ServiceException', 'States.TaskFailed'],
'IntervalSeconds': 2,
'MaxAttempts': 3,
'BackoffRate': 2.0
}],
'Catch': [{
'ErrorEquals': ['PaymentDeclined'],
'Next': 'NotifyPaymentFailed',
'ResultPath': '$.error'
}],
'Next': 'FulfillOrder'
}Wait States and Callbacks
A Wait state pauses workflow execution for a fixed duration or until a specific timestamp. A Callback pattern (using .waitForTaskToken) pauses execution until an external system calls SendTaskSuccess or SendTaskFailure with the token. This is how Step Functions models human approval steps: send an email with the task token, and the workflow resumes when a human clicks an approve/reject link in their email client.
# Callback pattern: wait for human approval
'RequestApproval': {
'Type': 'Task',
'Resource': 'arn:aws:states:::sqs:sendMessage.waitForTaskToken',
'Parameters': {
'QueueUrl': 'https://sqs.us-east-1.amazonaws.com/123/approvals',
'MessageBody': {
'taskToken.$': '$$.Task.Token',
'orderId.$': '$.orderId'
}
},
'Next': 'ProcessApproval'
}Step Functions and EventBridge Integration
Step Functions executions can be started by EventBridge rules, making it easy to trigger workflows in response to AWS service events. For example, an S3 ObjectCreated event triggers an EventBridge rule that starts a Step Functions image-processing workflow. Step Functions can also publish its own events to EventBridge when executions succeed or fail, enabling downstream monitoring and alerting without polling the Step Functions API.
Monitoring Step Functions Executions
The Step Functions console provides a visual workflow execution diagram showing which state succeeded, which is running, and which failed — colour-coded in real time. Each execution stores its full input/output history for Standard workflows (90-day retention). For Express workflows, logs go to CloudWatch Logs. Use X-Ray tracing to trace end-to-end request latency across Lambda functions and other services called within the workflow.
# List recent executions and check status
aws stepfunctions list-executions \
--state-machine-arn arn:aws:states:us-east-1:123456789012:stateMachine:OrderProcessing \
--status-filter FAILED
# Describe a specific failed execution for debugging
aws stepfunctions describe-execution \
--execution-arn arn:aws:states:us-east-1:123456789012:execution:OrderProcessing:exec-001Step Functions vs SQS vs EventBridge
Knowing when to use Step Functions versus SQS or EventBridge is a common exam decision point. Use Step Functions when you need visible, stateful orchestration of a multi-step process with error handling and branching. Use SQS for reliable point-to-point async messaging between two services with retry via visibility timeout. Use EventBridge for event routing to multiple subscribers based on content patterns. A Step Functions workflow can integrate all three: wait for an SQS message via a task token, publish completion to EventBridge, and chain Lambda and SDK calls.
Quick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: Step Functions orchestrates workflows as state machines with Task, Choice, Parallel, Map, Wait, and Catch states, Standard Workflows support up to 1 year with full execution history while Express Workflows handle high-throughput sub-5-minute workloads, and the Callback pattern with task tokens enables human-in-the-loop approval steps. Next up we explore Kinesis Data Streams for high-throughput real-time event processing.
Frequently asked questions
Is the “Step Functions: Orchestrating Serverless Workflows” lesson free?
Yes — the full text of “Step Functions: Orchestrating Serverless Workflows” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “Step Functions: Orchestrating Serverless Workflows”?
Define multi-step workflows as state machines in Step Functions, handle errors with catch and retry blocks, and integrate native SDK integrations. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Step Functions: Orchestrating Serverless Workflows” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- EventBridge: Event Bus and Rules
- Step Functions: Orchestrating Serverless Workflows
- Kinesis Data Streams for Real-Time Event Processing
- Choreography vs Orchestration Patterns