Orchestrating Complex Tasks with AWS Step Functions
Complex operational tasks have many steps, must wait for slow operations, need retries and error paths, and sometimes need a person's approval. AWS Step Functions coordinates such tasks as state machines with built-in error handling and visual execution history. This lesson explains workflow types, states, service integration patterns, error handling, large-scale parallel processing with the Distributed Map state and human approval with callbacks.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish between Standard and Express workflows and choose the right type.
- Describe the state types and how data flows between states.
- Explain the request-response, run a job (.sync) and wait for callback integration patterns.
- Explain Retry and Catch error handling and how the Distributed Map state processes items at large scale.
Why Orchestrate
Chaining Lambda functions, where each calls the next, hides the workflow in code, makes error handling inconsistent and loses visibility when something fails half-way. A state machine in Step Functions declares the workflow in Amazon States Language (JSON), and Step Functions runs it, records every state transition, retries failures as configured and shows each execution graphically. Automations that would otherwise need custom code for waiting, polling and recovery become declarative.
Standard and Express Workflows
Step Functions offers two workflow types with different guarantees and pricing.
Operational automation, such as patch orchestration, account provisioning, incident response and deployments, almost always uses Standard workflows because it is long-running, must not repeat steps and needs an audit trail. A failed Standard execution can be redriven from the failed state after the cause is fixed, without rerunning successful steps.
Standard or Express?
States and Data Flow
A state machine consists of states, each of which does one thing. The state types are summarised below.
| State | Purpose |
|---|---|
| Task | Performs work: invokes Lambda, calls an AWS service through an integration, or runs an activity |
| Choice | Branches based on input values |
| Parallel | Runs fixed branches at the same time and waits for all |
| Map | Runs the same steps for each item in an array (inline) or in a large dataset (distributed) |
| Wait | Pauses for a duration or until a timestamp |
| Pass | Passes or transforms data without work |
| Succeed and Fail | End the execution with success or failure and an error and cause |
Each state receives JSON input and produces output. Data can be selected and transformed with JSONPath fields (InputPath, Parameters, ResultSelector, ResultPath, OutputPath) or, in newer state machines, with JSONata expressions and variables, which simplify passing data between non-adjacent states.
Service Integration Patterns
Task states call services directly through optimised integrations for common services and AWS SDK integrations for over 200 services, so many workflows need no Lambda functions at all. Each integration uses one of three patterns, chosen by the suffix of the resource ARN.
Request-response
Step Functions calls the API and moves on as soon as it receives the HTTP response, for example arn:aws:states:::sns:publish. Used when the call itself is the work.
Run a job (.sync)
Step Functions starts a job and waits until it completes, for example arn:aws:states:::ecs:runTask.sync, codebuild:startBuild.sync or states:startExecution.sync for a nested workflow. Step Functions handles polling, so the workflow waits for a 40-minute build without any code.
Wait for callback (.waitForTaskToken)
Step Functions passes a task token to a service, such as an SQS message, an SNS notification or a Lambda function, and pauses until something calls SendTaskSuccess or SendTaskFailure with that token, or until a heartbeat or overall timeout expires. This is the pattern for human approval: the token is sent in an email link or chat message, and the approver's action calls back through API Gateway and Lambda. It also integrates external systems that finish work later.
Choose the integration pattern
Error Handling
Every Task, Parallel and Map state can have Retry and Catch fields. A Retry rule matches error names, such as States.TaskFailed, States.Timeout, Lambda.TooManyRequestsException or a service error, and retries with an interval, a maximum number of attempts, a backoff rate, an optional maximum delay and jitter. A Catch rule handles errors that remain after retries by moving to a fallback state, such as a notification, a compensating action that undoes earlier steps, or a Fail state. Timeouts (TimeoutSeconds and HeartbeatSeconds) prevent a task from waiting forever.
"CreateSnapshot": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:ec2:createSnapshot",
"Arguments": {"VolumeId": "{% $volumeId %}", "Description": "pre-patch"},
"Retry": [{"ErrorEquals": ["Ec2.RequestLimitExceeded", "States.TaskFailed"],
"IntervalSeconds": 5, "MaxAttempts": 4, "BackoffRate": 2.0, "JitterStrategy": "FULL"}],
"Catch": [{"ErrorEquals": ["States.ALL"], "Next": "NotifyFailure"}],
"Next": "WaitForSnapshot"
}The following diagram shows the order of Retry and Catch.

Large-Scale Processing with the Distributed Map State
Inline Map processes up to 40 concurrent iterations of an array inside one execution. The Distributed Map state is designed for large datasets: it reads items from a large JSON array, a CSV file, an S3 inventory report or a list of S3 objects, and runs a child workflow execution for each item or batch of items, with up to 10,000 child executions running in parallel. It supports a tolerated failure percentage or count and writes results to S3. Operational uses include checking or re-tagging millions of S3 objects, running a check against every account in an organisation, or processing a large backlog of log files.
Starting and Monitoring Workflows
State machines are started by EventBridge rules (for events) and EventBridge Scheduler (for schedules), by API Gateway, by other state machines, by Systems Manager Automation or by CodePipeline Step Functions invoke actions. Execution status changes are published to EventBridge, so failed executions can raise notifications, and CloudWatch metrics such as ExecutionsFailed and ExecutionsTimedOut support alarms. X-Ray tracing can be enabled to see latency across the services a workflow calls.
Orchestrated Instance Maintenance
Every month, a team must, for each of 300 application instances: remove it from its target group, wait for connections to drain, snapshot its volumes, apply an update with Run Command, verify health and return it to service, with no more than 10% out of service at once. Failures must stop that instance's maintenance and notify the team, and the change board must approve the start.
-
Approval
The first state publishes an approval request with a task token (.waitForTaskToken) and waits up to 24 hours.
-
Fan out
A Map state iterates over the instance list with MaxConcurrency of 30.
-
Per instance
SDK integrations deregister the target, a Wait state allows draining, EC2 snapshot calls run with Retry, Run Command applies the update, and a Choice state checks target health.
-
Failure path
Catch rules route failures to an SNS notification and stop only that iteration, and the Map state's failure tolerance allows the rest to continue.
A workflow must start an AWS CodeBuild project that runs for 30 minutes and continue only when the build finishes. Which integration pattern should the Task state use?
Show answer
The run a job pattern, codebuild:startBuild.sync, in a Standard workflow. Step Functions waits for the build to complete without a polling function.
Exam Tips
Remember for the exam
- Standard workflows run up to one year with exactly-once steps and history; Express workflows run up to five minutes for high-volume events.
- Request-response returns immediately; .sync waits for jobs such as ECS tasks or CodeBuild builds; .waitForTaskToken waits for SendTaskSuccess, used for human approval.
- Retry (interval, attempts, backoff, jitter) and Catch (fallback states) handle errors; timeouts and heartbeats prevent indefinite waits.
- AWS SDK integrations call over 200 services without Lambda; Distributed Map runs up to 10,000 parallel child executions over large datasets.
- Failed Standard executions can be redriven from the failed state.