AWS Step Functions is a fully managed service that enables coordination of serverless functions, your applications and AWS services through workflows. Each workflow is like a state machine diagram that consist of multiple steps, with one step’s output feeding as input into next step.
Step Functions service maintains a state of the application through each step, and determines which step to trigger next, while also handling the errors and logging as execution takes place.
Following diagram shows a simplified view of how Step Functions works:
Image courtesy of AWS
Key Components of AWS Step Functions
State Machines
State Machines describe your workflow as a series of steps, their relationships, and their inputs and outputs.
- Each step represents a State, and each State can do one of the following operation:
- perform work,
- make choices,
- pass parameters,
- initiate parallel execution,
- manage timeouts, or
- terminate your workflow with a success or failure
- State Machines are defined in JSON-based Amazon States Language.
- You can make API calls directly from this definition.
Tasks
A Task is how State Machine performs work. There are two types of Tasks in Step Functions:
- Activity Tasks – these tasks allow a Step to get work done by application code that may be hosted within AWS, or on on-prem servers, or on mobile phones / capable IoT devices.
- These externally hosted application components are called Workers
- Workers’ function may be coded in any language – the only requirement is that these workers be able to make web service API calls.
- These tasks work on Pull mechanism – that is – the Workers periodically poll State Machines for available tasks.
- Service Tasks – these tasks allow a Step to connect with a supported AWS service and submit request for the task.
- These tasks work on Push mechanism – that is – the State Machine submits the request(s) to AWS service.
- Examples of Service Tasks:
- Invoke a Lambda function
- Publish to an SNS Topic
- Send a message to SQS queue
- DynamoDB reads / updates
- Launch another Step Functions execution
Key Points
- Step Functions is a fully managed service.
- Step Functions is highly available, and scales automatically.
- Step Functions has a graphical console for visual composition of the workflow that consists of your application components.
- Step Functions stores state at each step, and thus enables resuming of the execution flow even if some failure were to cause interruption.
- You can run your tasks in the AWS Cloud, on your on-prem servers, or any environment that has access to AWS.
- Step Functions is SOC compliant and HIPAA eligible.
Standard vs Express Workflows
Each State Machine at the time of creation is marked either Standard or Express workflow type.
- Standard Workflows are best suited for long running executions, whereas Express Workflows are best suited for high-volume shorter duration executions.
- Also, if you need to guarantee that any step must not be repeated, then you have to go with Standard Workflow
- Example – in case of eCommerce, you wouldn’t want payment be processed twice, or item be shipped more than once.
- You cannot change the type after State Machine has been created.
- Following table shows the comparison of the two types
Table courtesy of AWS
Step Functions vs Simple Workflow Service (SWF)
AWS recommends that for all your new applications, you should use Step Functions – since it’s much more advanced and new features continue to be added to this service.
The only exception for new applications to be based on SWF is when you need external signals to intervene your process execution, or you need result exchange between parent and child processes.
You are able to achieve this type of granularity because SWF allows you to write decider program that separate activity steps from decision steps.
Even though this adds complexity, it provides you with more control.
Pricing
Step Functions are priced differently for Standard Workflows and Express Workflows
Standard Workflows are charged based on following component:
- Number of State Transitions (Step execution) – per State Transition
- First 4,000 State Transitions are free per month
Express Workflows are charged based on following components:
- Number of Requests – per Request
- There is no free tier in this case
- Duration, along with Memory consumption
- Duration (workflow execution begin to end) – per millisecond (rounded up to 100 milliseconds)
- Memory consumption (in 64 MB chunks) – per GB-hours
- This pricing has a tiered approach like:
- $0.00000X per 100 milliseconds for first 1,000 GB-hours
- $0.00000Y per 100 milliseconds for next 4,000 GB-hours
- $0.00000Z per 100 milliseconds for additional GB-hours
Any additional AWS service invoked as a result of Step Functions step execution would have its standard charges applied.
External Resources