VOOZH about

URL: https://www.geeksforgeeks.org/devops/aws-steps-functions/

⇱ How to Create AWS Step Function Workflow with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create AWS Step Function Workflow with Examples

Last Updated : 23 Jul, 2025

AWS Step Function allows you to automate and coordinate multiple AWS Services to build powerful workflows. It helps you to breakdown complex processes into smaller, manageable steps, simplifying the management of operations like microservices, orchestration, error handling, and more.

In this tutorial, we will go through a step-by-step process to implement a basic workflow for processing articles in geeksforgeeks. We will use AWS Lambda function to automate updating article status in a content management system, also show you how to build and manage each step of the workflow.

By the end of this tutorial, you'll not only understand how to create a Step Function workflow, but also how to use AWS services to create seamless automation for real-world applications.

What is AWS Step Functions?

AWS Step Function is a serverless orchestration service that helps developers use AWS service to build distributed applications, automate processes, orchestrate microservices, and create data and machine learning (ML) pipelines.

For example, if you're building a process that needs to send an email after as user signs up, Step Functions can help you connect different tasks like sending the email, checking the user's information or logging the action in a database - all in one automated workflow.

Key Terminologies

1. State Machine

A state machine controls the workflow or flow of execution of tasks. A state machine is responsible for how tasks are executed and how different variables are managed during the process. State Machine are of two types: Standard and Express. Standard state machines are generally used for long running tasks while Express state machines are better for high workload tasks.

2. State

A State is any action or step taken in a step machine that involves a variable. A state can be of different type depending on the type of function it performs such as task state(performs a task), choice state(choosing between variables) etc.

3. Task

In a state machine, each individual step or action is called a task. Tasks are often used to tell AWS services to do something.

4. Execution

When a state machine starts running (is triggered), it creates an execution. This execution manages the entire process of the state machine or workflow.

5. Error Handling

When Something goes wrong (an error occurred) inside the state machine, you need special instructions to deal with it. This process of identifying and handling errors is called error handling. Similar to state machine, rules for error handling can be define by writing and editing a JSON file.

How to Create your First AWS Step Function Workflow: Step by Step Guide

Let's see how to build serverless workflows using the step function. We will build a simple workflow for GFG articles.

The state machine will contain a prototype design that will change the article status depending on the previous status.

Step 1: Open the AWS Step Functions Dashboard

  • Before starting, first log in to the AWS console. On the console, go to search and open the AWS step functions. You should see a similar page below.

👁 AWS Console Step Function

  • Click on Get started.

👁 AWS step functions

  • select Create Your own from options.

Step 2: Create Prototype for workflow:

Select "Create your Own": Click on "Create Your Own" option to begin designing your workflow.

On Prototype design page follow below steps to create prototype for our workflow.

1. Add Lambda Invoke: From left navigation pane, drag and drop Lambda Invoke state between start and end states.

👁 Prototype design

2. Name the Lambda Invoke State: In left pane give name to this state as "GeeksForGeeks Article Description". This state will take article description as a input and pass it to next state.

3. Add a Choice State: Now similarly drag and drop Choice state from flow in left pane. There will be two rules namely Rule 1 and default. from left pane under rules section click on add new choice rule. This will add another rule.

4. Now for rule 1 and rule 2 add AWS lambda states as next state and name them as "Add To Review" and "Move To Publish" respectively.

5. Modify default rule: Click on default rule and under next state specify as Add To Review. Finally, the flow should look like below.

👁 Prototype

6. Add Another Lambda State: Now add one more lambda state under Add To Review and name it as "Show Article". Now modify first two states where next step will be "Show Article". Finally, the state machine will look like below.

👁 Prototype design

Step 3: Define Conditions for Each Rule

Now in choices click on Rule 1 and in left pane under conditions click on edit icon. Specify condition as below which will check if the article status is equal to pending or not. Click save condition after completion.

👁 Conditions

  • Similarly add condition for Rule 2. For rule 2 value of comparison is "Review".
  • Now we are done with prototype design.

Do not close this tab go to another tab for next step.

Step 4: Create Lambda Functions

Now let's create lambda functions to invoke and add them to states.

  • From navigation go to lambda functions and click on create function.
  • For first function specify name of function and leave everything as default and click on create.

👁 Specify Name

  • On successful creation of function on details page go to code source. Add serverless logic for execution and click on deploy. Here we have logic as below.

👁 Function Deployed

export const handler = async (event) => {
const {
status,
name
} = event;

const articleDescription = {
name : name,
status : status
};
return articleDescription;
};


  • Similarly create another function with name "MoveToPublish" and add following code.

👁 MoveToPublish

export const handler = async (event) => {
const {
status,
name
} = event;

const updatedDescription = {
name : name,
status : "Publish"
};
return updatedDescription;
};


  • Now create another function with name "AddToReview" and add following code.

👁 AddToReview

export const handler = async (event) => {
const {
status,
name
} = event;

const updatedDescription = {
name : name,
status : "Review"
};
return updatedDescription;
};


  • At last, create our last function "ShowArticle" and add below logic.

👁 ShowArticle

export const handler = async (event) => {
const {
status,
name
} = event;

const Description = {
name : name,
status : "Review"
};
return Description;
};


Step 5: Add Lambda Functions to States

Once all functions are created add the respective function to each state. Go to previous tab and click on first state. In left pane under API parameter select respective lambda function from function name dropdown.

👁 API Parameter

  • Now add functions for other states also

This will complete our state machine. On verification click on create.

Step 6: Executing Step function

On state machine overview page click on start execution. Add input for our execution as below.

👁 Execution

  • Click on start Execution. New IAM role will be added for execution where click confirm and continue.
  • On successful execution scroll down to see Graph View and click on "Show Article" state to view the output.

👁 Show Article

As we can see the flow of execution and the output where the status of article is changed to "Review" from "Pending"

  • Similarly create another execution with input status as "Review" you should see following flow of execution.

👁 Review

Examples

Example 1: Creating a workflow for a order processing application.

Consider an application that handles processing of orders. This can be done in several steps where the application needs to validate, process, update and send confirmation on the orders. Using AWS step functions, the workflow will look like this:

  • ValidateOrder: This step is used to validate customer order or checking the availability of order.
  • Process Payment: This is used to process the payment by a suitable payment method and gateway.
  • UpdateInventory: This will update the no of available items in the inventory after an order has been validated.
  • SendConfirmation: This will send a confirmation to the customer upon confirming the order.

A JSON file can be used to define the state machine and all these variables:

{
"StartAt": "ValidateOrder",
"States": {
"ValidateOrder": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:ValidateOrderFunction",
"Next": "ProcessPayment"
},
"ProcessPayment": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:ProcessPaymentFunction",
"Retry": [
{
"ErrorEquals": ["PaymentFailed"],
"IntervalSeconds": 5,
"MaxAttempts": 3,
"BackoffRate": 2
}
],
"Next": "UpdateInventory"
},
"UpdateInventory": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:UpdateInventoryFunction",
"Next": "SendConfirmation"
},
"SendConfirmation": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:SendConfirmationFunction",
"End": true
}
}
}
👁 Creating a workflow for a order processing application.

Example 2: Creating a workflow for a data processing pipeline.

Consider a data processing pipeline that is used for data extraction, transformation o f data and loading of data into a database. AWS step functions can be used to create a workflow with variables such as:

  • ExtractData: This will help in retrieving the data from a data source.
  • TransformData: This will help in transformation of data via a lambda function.
  • LoadData: This is used to load the transformed data into a database table such as DynamoDB table.

A JSON file in Amazon State Languages will look something like this:

{
"StartAt": "ExtractData",
"States": {
"ExtractData": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:ExtractDataFunction",
"Next": "TransformData"
},
"TransformData": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:TransformDataFunction",
"Next": "LoadData"
},
"LoadData": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:LoadDataFunction",
"End": true
}
}
}
👁 6

Conclusion

AWS Step Function is a great tool for automation workflows in the cloud. It makes it easy to connect different AWS services, manage the execution of tasks, and handle errors automatically. Whether you're working on a simple task or a complex workflow, Step Function helps you manage your processes without worrying about servers or infrastructure.

By using AWS Step Functions, you can streamline your tasks, improve reliability, and build powerful workflows that save time and reduce manual intervention.

What is the difference between AWS step functions and AWS lambda?

AWS step functions is a service to manage tasks and applications while AWS lambda is used to run code. Step functions can call lambda functions inside the workflow.

Can AWS step functions be integrated with other AWS services?

Yes, it is possible to integrate other AWS services such as S3 bucket, Lambda etc.

Is visualization of workflow possible with AWS step functions?

Yes, AWS step functions are an excellent way to manage and visualize workflow in an application. The visual editor available in AWS step functions provides a hassle free way to visualize the workflow.

How can errors be handle in AWS step functions?

Errors can be handled by providing a rules on failures such as repeat on failure, halt on failure and fallback states etc.

Is AWS step functions suitable for long running tasks or short running tasks?

AWS step functions are suitable for both long running and short running applications. We can define time states and wait states to manage long running workflow.

Comment
Article Tags: