AWS Step Functions

AWS Step Functions is an orchestration service that can be integrated with many other Amazon services, such as Lambda and SNS. Using Step Functions, we can create workflows—known as state machines—where each state can be integrated with a service.

Press + to interact

Apart from service integrations, states can also perform several different kinds of actions, such as evaluating conditional statements and choosing between different branches of execution. They can also pass data through to the following state, perform different actions in parallel, or iterate over steps.

State machine executions are asynchronous—they can pause for extended periods (up to a year) while waiting for a callback to resume execution. To achieve this, the state machine creates a task token and pauses execution. It then waits for a callback, including the same token, to resume.

Workflows in Step Functions

AWS Step Functions support two types of workflows: standard and express. In a standard workflow, each step is executed exactly once (unless retrying is specified in the ASLAmazon stats Language), and these workflows can run up to a year. These workflows are ideal for long-running auditable workflows.

However, in express workflows, each step is executed at least once, and there is a chance some steps are executed more than once. These workflows can run up to five minutes and are used in applications where high-event-rate workloads are required, such as streaming data processing applications.

Express workflows

In Express Workflows, we have two further options to choose from:

  • Asynchronous Express workflows: These workflows don’t wait for the workflow to complete. However, they do return a confirmation once the workflow has started. These workflows are used when an immediate response output is not required by our application.

  • Synchronous Express workflows: Once these workflows start, they wait for the workflow to finish execution and then send a response. These workflows are typically used in orchestrating microservices.

States in Step Functions

In AWS Step Functions, a state is a basic element of the state machine that can make a decision based on the input it receives, process this input, and pass an output to other states. Following are the states supported by AWS Step Functions:

  • Pass: This state passes the input it receives as output without performing any action on it.

  • Task: This state performs actions using AWS services, such as Lambda functions or other third-party services.

  • Choice: This state adds conditional logic to our state machine.

  • Wait: This state is used to add delay into our state machine.

  • Succeed: This state successfully stops the state machine. It is usually used with conditional states where we have nothing to do if a condition is met.

  • Fail: This state ends the state machine in failure.

  • Parallel: This state is used to add multiple branches to our state machine, which can be executed in parallel.

Press + to interact
States in a state machine
States in a state machine

AWS Step Functions Workflow Studio

Workflow Studio for AWS Step Functions provides us with a user-friendly, low-code visual interface for creating serverless workflows that orchestrate various AWS services. With its drag-and-drop feature and integrated code editor, we can easily design and customize workflows, adjusting input/output filtering and transformations for each state and configuring error handling as required.

The workflow designer has three main components:

  • Canvas: This is where we can drag and drop states and flow elements to design our workflow.

  • States browser: This is found on the left panel; this is where we can find the different types of states that we can use to define our workflow.

  • Inspector: This is found on the right panel; this is where we can configure the states in our workflow.

Use case: Build an e-commerce application

AWS Step Functions allow us to build applications by converting their different components into a series of individual steps. Each step can invoke a Lambda function, update our database, or perform other actions according to our requirements.

Let’s consider we want to build an e-commerce application where users can perform multiple actions, such as they can place orders, requesting items that are not available, etc. AWS Step Functions can be used to orchestrate the different components of this application. To do this, we’ll have to divide the features of our application into different tasks. For example, sending a notification to a customer once their order is confirmed is one task. We can also integrate AWS services such as Amazon DynamoDB and Amazon SNS in AWS Step Functions to automate and orchestrate our application components.

Best practices

The following practices can help us optimize the implementation of our Step Functions:

  • Timeouts: By default, AWS Step Function relies on the output it receives to move ahead. To avoid getting stuck if an output is not generated due to some erroneous condition, we advise providing an explicit timeout in our state machine.

  • Using S3 buckets: Rather than providing large payloads of data to our state machine, it is advised to upload this data into S3 buckets and then use these buckets in the state machine.

  • Lambda exceptions: It is suggested to properly handle the errors faced by Lambda functions, such as execution timeout errors, by providing a retry policy or a catch block in the state machine.

Pricing in Step Functions

AWS Step Functions follows the pay-as-go model and we are charged on the basis of the type of workflow we use. In the standard workflow, we are charged on the number of state transistions required to execute our application. In express workflows, we are charged on the duration of our workflow in adition to the number of requests made to the workflow. Here, duration refers to the time it takes to start the execution of the state machine until it is terminated.

Additional charges might be made in case we use different AWS services in our workflow or transfer data.

Get hands-on with 1300+ tech skills courses.