Study guide
Technical reference and lesson notes
Purpose of This Lesson
AWS Step Functions is a managed orchestration service for coordinating distributed application workflows. It lets you define a sequence of states, invoke AWS services such as AWS Lambda, apply branching logic, wait for a period, handle errors, and track execution progress.
Step Functions is especially useful when an application requires more control than a simple event trigger can provide. Instead of embedding orchestration logic inside one large Lambda function, the workflow is represented explicitly as a state machine.
Key Concepts
State machines and executions
A state machine is the definition of a workflow. It describes the states, transitions, inputs, outputs, and error-handling behavior.
An execution is a running instance of that state machine. Each execution has its own input, state transitions, output, and execution history.
A typical workflow might look like this:
- Receive an input event.
- Invoke a Lambda function to process the input.
- Evaluate the result with a
Choicestate. - Follow a success or failure branch.
- Wait for a specified duration if required.
- Invoke another function or AWS service.
- End with
SucceedorFail.
Amazon States Language
Workflows are defined using Amazon States Language (ASL), a JSON-based language for describing state machines. The definition can be created or edited in the AWS Management Console, but infrastructure-as-code tools such as AWS CloudFormation, AWS CDK, and Terraform are generally preferable for repeatable deployments.
Common ASL state types include:
| State type | Purpose |
|---|---|
Task | Performs work by invoking Lambda or an integrated AWS service/API. |
Choice | Branches based on input or task output. |
Wait | Delays execution for a duration, timestamp, or input-derived value. |
Parallel | Runs multiple branches concurrently and waits for them to complete. |
Map | Iterates over items, optionally processing them concurrently. |
Pass | Passes or transforms data without calling an external service. |
Succeed | Ends successfully. |
Fail | Ends unsuccessfully. |
Data passing between states
Step Functions passes JSON data between states. A task can receive workflow input, perform work, and return a result for a later state. ASL fields such as InputPath, Parameters, ResultSelector, ResultPath, and OutputPath help control which data is selected, constructed, merged, or passed onward.
This makes it possible to keep each function focused on a specific responsibility while the state machine controls the overall sequence and data flow.
Branching and waiting
A Choice state implements conditional logic without requiring a Lambda function solely to evaluate a simple condition. For example, a workflow can inspect a processing status and route the execution to an approval branch or a notification branch.
A Wait state pauses the workflow for a fixed number of seconds, until a timestamp, or for a value provided in the input. This is useful for delayed processing, polling intervals, approval windows, and scheduled follow-up actions.
Error handling
Step Functions supports workflow-level error handling through Retry and Catch configuration on task states.
- Retry repeats a failed task using configurable error matching, backoff, and attempt limits.
- Catch routes an error to a fallback state, such as a compensation step, notification, or failure-handling branch.
- A terminal
Failstate makes an unsuccessful outcome explicit.
This is usually preferable to implementing all retry and branching behavior manually inside application code, but task operations should still be designed to be idempotent. A retry can cause the underlying operation to run more than once.
Service integrations
Step Functions can invoke Lambda and many AWS services directly through service integrations. Direct integrations can reduce the amount of coordination code and avoid using Lambda as a wrapper around an API call.
For example, a workflow might invoke an AWS Lambda function for custom business logic, call an Amazon DynamoDB API directly for persistence, or start an AWS Batch or Amazon ECS task for longer-running compute. The exact integrations and supported patterns depend on the service and Step Functions integration mode.
Standard and Express Workflows
Step Functions provides two workflow types:
| Characteristic | Standard Workflows | Express Workflows |
|---|---|---|
| Best suited for | Long-running, durable, auditable business processes | High-volume, short-duration event processing |
| Execution history | Detailed execution history and visual tracking | More limited execution-history model; use logging and monitoring appropriately |
| Execution duration | Up to one year | Up to five minutes |
| Delivery behavior | Exactly-once workflow execution semantics, subject to task and integration behavior | At-least-once or effectively-once processing considerations depending on mode and integration |
| Typical examples | Order fulfillment, approvals, financial processing | Streaming transformations, IoT or event-driven processing |
Express Workflows have synchronous and asynchronous invocation modes. Choose the workflow type based on duration, throughput, execution-history requirements, and delivery semantics—not simply because one option is cheaper.
Exam-Relevant Takeaways
- Use Step Functions when the main problem is orchestration, including sequencing, branching, waiting, parallel processing, retries, and error handling.
- Use a
Choicestate for decision logic rather than creating a Lambda function for every simple yes/no decision. - Use a
Waitstate for delayed transitions instead of keeping a Lambda function running while it sleeps. - Use
ParallelorMapwhen independent work can be performed concurrently. - Consider direct AWS service integrations to reduce unnecessary Lambda functions and custom glue code.
- Design tasks for idempotency because retries, timeouts, client retries, or duplicate events can cause repeated operations.
- Standard Workflows are the usual choice for durable, long-running, inspectable business processes.
- Express Workflows are appropriate for short-lived, high-volume workflows where throughput and cost efficiency are important.
- Step Functions provides orchestration, not general-purpose compute. The actual work is performed by Lambda, containers, AWS services, or other integrated systems.
- State-machine definitions can be visualized in the console, but production definitions should normally be managed through infrastructure as code and version-controlled.
Architecture Decision Guide
| Requirement | Recommended approach | Reasoning |
|---|---|---|
| Coordinate several Lambda functions with branching | Step Functions Standard Workflow | Makes sequencing and decisions explicit and observable. |
| Delay a follow-up action for minutes or hours | Wait state in Step Functions | Avoids holding compute while waiting. |
| Retry transient downstream failures | Retry configuration plus idempotent task design | Centralizes retry behavior and limits attempts. |
| Route failures to remediation or notification | Catch state transition | Allows a controlled fallback path. |
| Process many records independently | Map state, possibly with distributed processing | Represents iteration and can provide controlled concurrency. |
| Run independent branches at the same time | Parallel state | Expresses concurrent workflow paths. |
| Make a simple AWS API call | Direct Step Functions service integration | Avoids a wrapper Lambda when no custom code is needed. |
| Run a high-volume, short-lived workflow | Express Workflow | Optimized for short executions and high event rates. |
| Run an auditable approval or fulfillment process | Standard Workflow | Provides durable execution tracking and long-running support. |
| Implement a simple one-step event reaction | Lambda with an event source | Step Functions may add unnecessary orchestration overhead. |
Common Exam Traps
- Confusing orchestration with choreography: EventBridge, Amazon SQS, and Amazon SNS help decouple event producers and consumers, but they do not by themselves provide a stateful, ordered workflow with branching and retries across multiple steps.
- Using Lambda for waiting: A sleeping Lambda consumes runtime and can hit timeout limits. Use a Step Functions
Waitstate for workflow delays. - Assuming Step Functions performs the business work: Step Functions coordinates tasks; it does not replace Lambda, ECS, Batch, DynamoDB, or other services that perform the work.
- Ignoring duplicate execution effects: A retry does not guarantee that a failed task had no side effects. Use idempotency keys, conditional writes, or transaction controls where appropriate.
- Choosing Express for a long process: Express Workflows have a short maximum execution duration and are not the default choice for multi-day or highly auditable workflows.
- Adding Lambda wrappers unnecessarily: If Step Functions can call the required AWS API directly, a wrapper function may add code, latency, permissions, and operational overhead.
- Treating the visual graph as the deployment mechanism: The console visualization is useful for understanding and troubleshooting a workflow, but deployment should be controlled through versioned configuration and infrastructure as code.
- Putting sensitive data everywhere in workflow input: State data can appear in execution history and logs depending on configuration. Minimize sensitive payloads and use references to protected data where appropriate.
Real-World Engineer Notes
- Give each task a clear contract: expected input, output, timeout behavior, and retryable errors.
- Use task timeouts so a stalled downstream dependency does not leave executions waiting indefinitely.
- Make external side effects idempotent. For example, use a unique order or transaction identifier and conditional writes when creating records.
- Keep workflow payloads small and pass object references, such as Amazon S3 keys, when large data must move between steps.
- Separate business decisions from execution details. A
Choicestate can route based on a status returned by a task, while the task remains focused on producing that status. - Apply least-privilege IAM permissions to the state-machine execution role and to individual integrated services.
- Monitor execution failures, timeouts, retries, throttling, and duration with Amazon CloudWatch metrics and logs. Standard execution history is particularly useful for diagnosing which state failed.
- Consider compensation actions for partially completed workflows. For example, if inventory is reserved but payment fails, a failure branch may release the reservation.
- Control concurrency for
Mapworkloads to avoid overwhelming downstream services or exceeding service quotas. - Use Standard Workflows when operational staff need to inspect and replay or remediate individual business executions. Use Express when the workload is better treated as high-volume event processing and detailed per-execution history is less important.
Quick Reference Summary
- Service purpose: Managed orchestration for distributed workflows.
- Workflow definition: Amazon States Language, represented as JSON.
- Primary building block: State machine.
- Running instance: Execution.
- Core logic:
Task,Choice,Wait,Parallel,Map,Retry, andCatch. - Compute model: Step Functions coordinates work performed by Lambda, containers, Batch, and integrated AWS services.
- Long-running and auditable: Standard Workflow.
- Short-duration and high-volume: Express Workflow.
- Most important design concern: Make task side effects idempotent and handle retries safely.
- Operational benefit: Clear execution history and visual workflow representation.
Flashcards
- Q: What is AWS Step Functions primarily used for?
A: Orchestrating distributed application components as a stateful workflow with sequencing, branching, waiting, retries, and error handling.
- Q: What is a state machine?
A: The definition of a Step Functions workflow, including its states, transitions, inputs, outputs, and error behavior.
- Q: What is an execution?
A: A running instance of a state machine with its own input, progress, output, and history.
- Q: Which Amazon States Language state implements conditional branching?
A: Choice.
- Q: Which state pauses a workflow without consuming Lambda runtime?
A: Wait.
- Q: What is the difference between
RetryandCatch?
A: Retry attempts the failed task again; Catch routes the failure to another state.
- Q: When should a
Parallelstate be used?
A: When independent workflow branches should run concurrently.
- Q: When is a
Mapstate useful?
A: When the workflow must iterate over a collection and process each item, potentially with controlled concurrency.
- Q: Why must Step Functions tasks be idempotent?
A: Retries and duplicate delivery can cause a task’s side effect to occur more than once.
- Q: Which workflow type is designed for long-running, durable processes?
A: Standard Workflows.
- Q: Which workflow type is designed for short-duration, high-volume processing?
A: Express Workflows.
- Q: What is a benefit of direct service integrations?
A: They can invoke supported AWS APIs without requiring a Lambda wrapper.
Practice Questions
Question 1
A company processes customer orders through several stages: validate payment, reserve inventory, create a shipment, and notify the customer. Each stage may fail independently, and operations staff need to identify the exact stage and resume or remediate failed orders. Which architecture is most appropriate?
A. One Lambda function containing all processing logic
B. An Amazon SNS topic with independent subscribers and no workflow state
C. A Step Functions Standard Workflow with task states, retries, and failure branches
D. An Express Workflow with a five-minute execution limit
Correct answer: C
Explanation: A Standard Workflow provides durable orchestration, explicit sequencing, error handling, and execution visibility for a multi-step business process. The tasks should be idempotent so retries do not duplicate payments, reservations, or shipments.
Question 2
A workflow must wait 30 minutes after sending a customer approval request before checking whether the request was completed. Which design minimizes unnecessary compute consumption?
A. Invoke a Lambda function and use sleep for 30 minutes
B. Use a Step Functions Wait state
C. Poll continuously from an Amazon EC2 instance
D. Increase the Lambda function timeout and memory allocation
Correct answer: B
Explanation: A Wait state pauses the workflow without keeping a compute runtime active. The workflow can then transition to a status-checking task after the required delay.
Question 3
A Step Functions task creates a customer record in DynamoDB. The task times out after the write may already have succeeded, and Step Functions retries it. What is the most important design action?
A. Disable all retries for the workflow
B. Make the write idempotent using a stable identifier and conditional-write logic
C. Move the write into a longer-running Lambda function
D. Use an Express Workflow instead of a Standard Workflow
Correct answer: B
Explanation: A timeout does not prove that the side effect failed. A retry may repeat the write, so the operation should use an idempotency key or conditional expression to prevent duplicate records. Retry policy can still be retained for genuinely transient failures.
Question 4
A company receives a very high volume of short-lived events. Each event requires a workflow that completes within seconds, and the company does not need detailed long-term history for every execution. Which Step Functions option is the best fit?
A. Standard Workflow
B. Express Workflow
C. A Wait state lasting several hours
D. A single EC2 instance running a workflow scheduler
Correct answer: B
Explanation: Express Workflows are intended for high-volume, short-duration processing. The choice should still account for delivery semantics, monitoring requirements, and the five-minute execution limit.
Question 5
A workflow needs to call a supported AWS service API and then branch based on the API response. The development team proposes creating a Lambda function solely to call the API. What is the best recommendation?
A. Use a direct Step Functions service integration when supported
B. Replace Step Functions with an EC2-based scheduler
C. Put the API call in an Amazon SQS dead-letter queue
D. Use a Wait state before every API request
Correct answer: A
Explanation: Direct service integrations can remove unnecessary wrapper code, reduce operational overhead, and allow the state machine to handle the response and subsequent branching directly.