Starting State Machines
You can start a Step Functions execution using the following methods:
AWS Documentation
- The Step Functions console.
- The
StartExecution
API action. - Amazon EventBridge.
- Nested workflows (triggering a workflow from another workflow).
- Amazon API Gateway.
Integration Patterns
There are three integration patterns:
AWS Documentation
- Request Response: Step Functions waits for the HTTP response and then progresses to the next step. It does not wait for the job to complete.
- Run a Job (.sync): For certain services, Step Functions can wait for the job to complete before proceeding to the next state, using polling to check the job status.
- Wait for a Callback with Task Token: Step Functions waits for the job to complete before moving to the next state. Instead of polling, it waits for the task token to be sent by the other service.
Integration Overview
There are two ways to integrate AWS services with Step Functions:
AWS Documentation
- AWS SDK Integrations: Call any AWS service from a state machine using API actions (supports over 200 services).
- Optimized Integrations: API actions customized to provide enhanced functionality for workflows (supports about 20 services).
Call HTTPS API
You can call public or private APIs using the HTTP Task workflow state.
An EventBridge connection is required for authorization and network connectivity.
AWS Documentation
State machine
State machine (or workflow) - a series of event-driven steps (or states). Each step can call other AWS services or execute one of Step Functions' logic tasks (such as Wait, Choice, etc.).
AWS docs
Workflow types
There are two workflow types:
AWS docs
- Standard:
- 2000 executions per second and 4000 state transitions per second.
- Pay for the number of state transitions.
- Easier to debug.
- Supports "Run a Job" and "Wait for a Token" integration patterns (in addition to the request/response pattern).
- Can run for up to one year.
- Exactly-once execution.
- Express:
- 100,000 executions per second with nearly unlimited state transitions.
- Pay for the number and duration of executions.
- Only supports the request/response integration pattern.
- Can run for up to five minutes.
- At-least-once execution.
State
A state (or step) is a unit of work in the state machine. There are two types of states:
AWS docs
- Flow state: Controls the logic of the workflow. Examples include Choice, Wait, Parallel, and Map states.
- Task state: Executes an actual unit of work, such as making a call to another AWS service.
State structure
State machines are defined using JSON. States can occur in any order within the enclosing block, but their execution order depends on their configuration. Common state fields include:
AWS docs
- Type: The type of state.
- Next: The name of the next state.
- End: Indicates a terminal state (true).
- Comment: A description of the state.
- Assign: Stores variables.
- Output: Specifies and transforms the output from the state.
- InputPath: Defines the input to process.
- OutputPath: Defines the output to pass to the next state.
Transforming Data
Currently, there are two ways to define state machine transformations: JSONPath and JSONata (introduced at re:Invent 2024).
AWS Documentation
- JSONPath: Use intrinsic functions in Pass, Task, Parallel, or Map states.
- JSONata: A more flexible and concise method for transforming data.
Flow States
In a flow state, work is handled entirely by Step Functions, without requiring interaction with other AWS services.
AWS Documentation
JSONata and JSONPath
Use JSONata for new state machines. Consider the differences between JSONata and JSONPath to determine how and why to migrate.
AWS Documentation
Variables
Variables are used to store data for use in future steps.
You can define and assign values to variables in Pass, Task, Map, Parallel, Wait, and Choice states.
There is one reserved variable called
AWS Documentation
$states
, which contains:
- The original input to the state.
- The result of the state.
- Error output.
- The context object.
Handling Errors
There are two ways to handle errors in Task, Parallel, and Map states:
AWS Documentation
- Retry: If an error encountered by the state matches an entry in the
ErrorEquals
list, the task will retry. - Catch: If an error encountered by the state matches an entry in the
ErrorEquals
list, the workflow will proceed to the task defined in the Catch block.
Task Types
The Task state is the only state that performs actual work; all other Step Functions states handle workflow logic.
Task types include:
AWS Documentation
- Activity: A worker implemented and hosted by you (not supported by Express workflows).
- Lambda Functions: Invokes a Lambda function.
- Supported AWS Services: Calls API actions for supported AWS services.
- HTTP Task: Calls an HTTP endpoint.
Activity
Set up a worker outside of Step Functions.
An activity worker can be any application capable of making an HTTP connection, such as one running on an Amazon EC2 instance, an AWS Lambda function, or even a mobile device.
AWS Documentation