Introduction to AWS Step Functions and How You Can Automate Your Workflows for Increased Efficiency

Hadi Haider
5 min readMay 9, 2023

--

An accessible walkthrough of the basics of AWS Step Functions

The use of serverless computing has become a must nowadays, and some of you may already know about Amazon Web Services. AWS Step Functions is a service provided by AWS, that combines AWS Lambda functions and other AWS services to build business-critical applications. AWS Step Functions is a serverless low-code service in the AWS Cloud for building workflows.

This article is made possible because of the course by Stephane Maarek on AWS Certified Developer Associate, I am able to share my insights on AWS Step Functions through this article.

What are Step Functions?

Step Functions are a Finite State Machine implementation offered as a serverless service by AWS. Step Functions are made of state machines (workflows) and tasks. Tasks are individual states or single units of work. Steps Functions creates a long-running, automated workflow for applications that require human interaction. Since it is a serverless orchestration server, it allows developers to create and manage multi-step application workflows in the cloud. It also helps to convert each task into visual workflows, which in turn helps to build and update the step function quickly.

Benefits of Step Functions:

With Step Functions, you can visually design, run, and debug workflows, enabling you to build highly scalable and reliable serverless applications. By breaking down your application logic into smaller, independent functions that can be executed in response to events, such as user actions or scheduled events, you can reduce operational overhead, improve application performance and scalability, and increase development agility.

Visual workflow in Step Functions
  1. With its visual interface, AWS Step Functions makes it easy to define and manage the flow of your application logic.
  2. AWS Step Functions can be integrated with other AWS services, such as Lambda, to create event-driven architectures.
  3. With AWS Step Functions, you can easily achieve automatic scalability for your serverless workflows.
  4. AWS Step Functions can automatically handle retries, manage errors, and orchestrate the execution of multiple functions, reducing the risk of service disruptions caused by application errors or failures.

State Types of AWS Step Functions:

Step Functions are based on the concepts of state machines and tasks.

A state machine is a computational model that describes the behavior of a system based on a set of states and transitions. In AWS Step Functions, a state machine is a visual representation of a serverless workflow that defines the steps needed to execute an application.

In AWS Step Functions, tasks are the primary means by which states perform work. They can execute specific actions by using an activity or a Lambda function, or by passing parameters to API actions of other services.

  • Choice State — Test for a condition to send to a branch (or default branch)
  • Fail or Succeed State — Stop execution with failure or success
  • Pass State — Simply pass its input to its output or inject some fixed data, without performing work.
  • Wait State — Provide a delay for a certain amount of time or until a specified time/date.
  • Map State — Dynamically iterate steps.
  • Parallel State — Begin parallel branches of execution

Types of Workflows:

Workflows are divided into two groups: Standard and Express workflow. Unlike Standard, the Express workflow is a relatively new option that has been available since last year. It’s important to note that Standard workflow is a long-running workflow that has to be durable and auditable. In contrast, the Express workflow type is needed for a much higher frequency and event processing volume.

Step Functions — Standard vs. Express

AWS Step Functions Best Practices

  • Resume process from the fail state — in a workflow, we sometimes need to resume the process from the fail state as opposed to re-running it from the beginning. For long-running executions, to avoid reaching the hard quota of 25,000 entries in the execution event history, AWS recommends that you start a new workflow execution directly from the Task state of a state machine. This allows you to break your workflows into smaller state machines, and to continue your ongoing work in a new execution. To start these workflow executions, call the StartExecution API action from your Task state and pass the necessary parameters.
  • Avoid infinite runs — State Machine can run infinitely. It has a max execution time of one year. On top of that, it provides a feature “Continue as new Execution”. This allows you to start a new execution before terminating your current running execution. This opens up the possibility of it running infinitely by mistake. Monitoring execution metrics is a good way to identify and fix those mistakes.
  • Handle timeouts — by default, the Amazon State Language doesn’t set timeouts in state machine definitions. In a scenario where a Lambda Function or Activity has a problem and keeps running without responding back to Step Functions, it will keep waiting for a year (max timeout) at least. To prevent this, set the timeout using TimeoutSeconds.

Use Cases of AWS Step Functions:

  • Workflow orchestration: AWS Step Functions can be used to orchestrate workflows and automate business processes. It can manage the flow of events and resources across distributed systems, making it easier to coordinate multiple functions and services.
  • Serverless applications: Step Functions can help build serverless applications that run on AWS Lambda, AWS Fargate, or EC2 instances. It enables developers to manage and coordinate the execution of serverless functions across distributed systems.
  • ETL workflows: AWS Step Functions can be used to create and manage ETL (extract, transform, load) workflows. It can help automate the movement and transformation of data between different systems, enabling data analysts and data engineers to focus on data analysis.
AWS Step Functions workflow for an ETL job

Conclusion:

  • AWS Step Functions enables increased efficiency, scalability, and agility by breaking down application logic into smaller, independent functions.
  • Workflows can be designed visually or in an easy to read Domain Specific Language (in Amazon States Language).
  • The service can integrate with other AWS services, providing automatic scalability for serverless workflows.
  • Two types of workflows are available: Standard and Express, each with its own benefits.
  • Following best practices is crucial to get the most out of AWS Step Functions, including resuming processes from a fail state, avoiding infinite runs, overcoming event entry limits, and handling timeouts.

Feel free to share your thoughts. You can reach out to me on Linkedin, or Twitter. You can check out all the source codes on Github.

--

--