AWS Step Functions Overview

Cem Onan
Orion Innovation techClub
4 min readJun 13, 2022

In this article, Amazon Web Services Step Functions Service will be covered.

WHAT IS THE STEP FUNCTIONS SERVICE?

Step Functions service can be considered as a concrete implementation of state machines. It’s a serverless orchestration service and allows you to create workflows by composing Lambda functions and other AWS services.

Workflow tasks are executed in a sequence, and each step is called a state. States and the execution sequence can be defined in either Amazon States Language (a JSON-based structural language) or Workflow Studio.

A screenshot from workflow studio.
Workflow Studio
Amazon States Language definition
Amazon States Language

State machines start with a JSON input. Each state takes the input and produces an output. The output of a state becomes the input of the next state.

ADVANTAGES OF STEP FUNCTIONS

  • It’s a fully managed service by AWS. This means that you don’t have to provision a host to execute tasks, or you don’t have to keep track of the states in a data source.
  • Supports hundreds of services on AWS with both optimized and SDK integrations.
  • It has advanced error handling and retries capabilities.

USE CASES

  • Web-based applications with human approval
  • IT Automation
  • Data processing pipelines and ETL orchestration
  • Media processing

STATE TYPES

  1. Task State

Task states represent the single unit of work done by using AWS Services. It can be executing a Lambda Function, sending a message to an SQS queue, fetching a record from the DynamoDB database, etc.

2. Pass State

Pass state is used to modify the input. The below example states that a passing state is configured to add notification templates to the input before they are sent to the customer.

Pass state example.
Pass State Example

3. Choice State

Choice states become handy when we want to add a conditional control flow. It can be thought of as switch/case statements.

Choice state example.
Choice State Example

As with all other state definitions in Amazon States Language, choice states support JSONPath syntax to dynamically access key-value pairs in the input.

The choice state supports the existence check and comparison operations with the following data types: Number, Timestamp (ISO-8601), Boolean, String, and Null. Conditions can be combined by using logical AND / OR operators.

An example choice state rule definition.
An Example Choice State Rule

4. Wait State

Wait state is used to delay the execution for a certain amount of time. Wait states can be specified to wait for either a fixed amount of seconds or up to a timestamp value. Both options can be configured either statically or dynamically by fetching the value from state input using JSONPath syntax.

For example, the wait state is configured to wait until a timestamp, which is fetched from state input.

Timestamp values should be compatible with the ISO-8601 standard.

Wait state example.
Wait State Example

5. Parallel State

A parallel state is used when we want to execute more than one branch simultaneously. So, tasks at the different branches do not have to wait for other branch executions to be completed. If a branch fails during the execution, the entire parallel state execution is considered as failed.

6. Map State

In the same way as the parallel state, the map state is used to execute the same steps for each entry in an input given as an array. Map state supports concurrent iteration. If concurrent iteration is limited to 1, the map state will wait for each iteration to be completed before moving to the next one.

RETRY LOGIC AND ERROR HANDLING

  1. Retriers

Retrier blocks can be configured to retry a task if specified error types occur. Error types can be identified as Amazon’s pre-defined templates (e.g. States.TaskFailed or States.Timeout) or you can use your own errors thrown inside the application code (e.g. java.lang.RuntimeException or com.example.CustomException)

Retrier block example.
Retrier Example

A backoff rate can be specified to increase the waiting time on each retry. The above example step function will wait 1 day before the first retry, 2 days before the second, and 4 days before the last retry attempt because the waiting interval is going to be multiplied by the backoff rate.

2. Catchers

Catcher blocks can be used to capture specific types of errors during task execution and then execution flow can be directed to another state called a fallback state.

Catcher example.
Catcher Example

REFERENCES

[1] https://aws.amazon.com/tr/step-functions/use-cases/ (2022–06–11)

[2] https://docs.aws.amazon.com/step-functions/index.html (2022–06–11)

[3] https://stackoverflow.com/ (2022–06–11)

--

--

Cem Onan
Orion Innovation techClub

Software Developer at Orion Innovation, cloud development enthusiast.