Theory
What are Step Functions?
From AWS Docs: Step Functions is a serverless orchestration service that lets you combine AWS Lambda functions and other AWS services to create business-critical applications. With the Step Functions graphical console, you see your application workflow as a series of event-driven steps. Step Functions is based on state machines and tasks. A state machine is a workflow. A task is a state in a workflow that is a unit of work that is being performed by another AWS service. Each step of the workflow is a state.
With the built-in Step Functions controls, you check the status of each workflow step to ensure that your application is running in the correct order and as expected. Depending on your use case, Step Functions can call AWS services such as Lambda to complete tasks. You can create workflows for processing and publishing machine learning models. You can use Step Functions to manage AWS services such as AWS Glue to create Extract, Transform, and Load (ETL) workflows. You can also create lengthy automated workflows for applications that require human interaction.
Or, in simple words, a service for managing your processes.
What are the possible use cases for Step Functions?
- Orchestration Lambda Functions
- Branching
- Exception handling (Retry or Catch)
- Human participation in the process
- Parallelism
Process types in Step Functions
- Standard - needed for processes running for a long time, has broad support for services and interaction options
- Express - needed for fast-running processes (5 minutes), saving ~ 20 times per million executed processes. Has less integration with AWS services
Types of Integration with AWS Services
Request a response (default) - Calls the service and allows Step Functions to go to the next state after receiving the HTTP response.
Run a job (.sync) - calls the service and waits for the job to complete.
Wait for a callback with a task token (.waitForTaskToken) - calls the service with the task token and waits for the task token to return using the callback.
Comparison of Integration with AWS Services in Standard and Express Types
Supported Service Integrations for Standard
Service | Request Response | Run a Job (.sync) | Wait for Callback (.waitForTaskToken) |
---|---|---|---|
Lambda | β | β | |
AWS Batch | β | β | |
DynamoDB | β | ||
Amazon ECS / AWS Fargate | β | β | β |
Amazon SNS | β | β | |
Amazon SQS | β | β | |
AWS Glue | β | β | |
SageMaker | β | β | |
Amazon EMR | β | β | |
CodeBuild | β | β | |
AWS Step Functions | β | β | β |
Supported Service Integrations for Express
Service | Request Response | Run a Job (.sync) | Wait for Callback (.waitForTaskToken) |
---|---|---|---|
Lambda | β | ||
AWS Batch | β | ||
DynamoDB | β | ||
Amazon ECS / AWS Fargate | β | ||
Amazon SNS | β | ||
Amazon SQS | β | ||
AWS Glue | β | ||
SageMaker | β | ||
Amazon EMR | β | ||
CodeBuild | β | ||
Step Functions | β | β |
Enough theory, let's go for example.
Theoretical example
In order to get at least some idea of ββwhat the service looks like, consider the Hello world example.
Preconditions
- AWS account
- Go to Step Functions service in AWS account
So the following is what we do:
- Go to "Create Step Functions"
- Define state machine = Author with code snippets
- Type = Standard
- Definition =
{ "Comment": "A Hello World example of the Amazon States Language using Pass states", "StartAt": "Hello", "States": { "Hello": { "Type": "Pass", "Result": "Hello", "Next": "World" }, "World": { "Type": "Pass", "Result": "World", "End": true } } }
Click Start execution. Insert can be omitted. You should see a diagram like this:
Congratulations, you've created the simplest Step Functions.
Instead of a conclusion
If this topic is interesting, in the next part we will create Step Functions with AWS Lambda + SQS + SNS integration, as shown in the diagram:
Links to sources:
https://docs.aws.amazon.com/step-functions/