> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to AWS Step Functions

> Hands-on lab · 30m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/introduction-to-aws-step-functions" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab Details

1. In this lab, you will be guided through the process of building a step function and integrating it with a Lambda function. You will practice it using AWS Step Functions.
2. Duration of the Lab : **30 minutes.**
3. AWS Region: **US East (N. Virginia) us-east-1**

### Introduction

#### AWS Step Functions

1. AWS Step Functions is a serverless function orchestrator that makes it easy to sequence AWS Lambda functions and multiple AWS services into business-critical applications.
2. You can create and run a series of checkpointed and event-driven workflows that maintain the application state with the help of visual interface.
3. The output of one step acts as an input to the next. Each step in your application executes in order, as defined by your business logic.
4. Orchestrating a series of individual serverless applications, managing retries, and debugging failures can be challenging.
5. Step Functions manages sequencing, error handling, retry logic, and state, removing a significant operational burden from you.

### Architecture Diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/001.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=fde68a1748bfbf75d61028fd66dc70d2" alt="" width="2773" height="1538" data-path="images/labs/introduction-to-aws-step-functions/001.png" />

### Task Details

1. Sign in to AWS Management Console
2. Create a Lambda Function.
3. Create a state machine in step function.
4. Test the step function

### Launching Lab Environment

1. To launch the lab environment, Click on the **Start Lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM user name**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

> **Note** : You can only start one lab at any given time

## Lab guide

### Lab Steps

#### Task 1: Sign in to AWS Management Console

1. Click on the **Open Console** button, and you will get redirected to AWS Console in a new browser tab.
2. On the AWS sign-in page,

   * Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
   * Now copy your **User Name** and **Password** in the Lab Console to the **IAM Username and Password** in AWS Console and click on the **Sign in** button.
3. Once Signed In to the AWS Management Console, Make the default AWS Region as **US East (N. Virginia) us-east-1.**

> **Note :** If you face any issues, please go through [**FAQs and Troubleshooting for Labs**](https://play.whizlabs.com/site/task_support/faqs-and-troubleshooting).

#### Task 2: Create a Lambda Function

In this task, we are going to create a Lambda function by providing the required parameters like name, runtime, execution rule etc.

1. Navigate to the  **Services** menu at the top, then click on **Lambda** under the **Compute** section.
2. Click on **Create a function** button.

   * Select **Author from Scratch**
   * Function Name : Enter ***MyStepFunction\_lambda***
   * Runtime : Select **Python 3.13**
   * Expand Adavanced Settings Option, Enable **Custom execution role**
   * Select **Lambdarole-\<RANDOM\_NUMBER>**

* Leave other options as default.
* Click on **Create function** button.

3. Once the Lambda Function is created successfully, it will look like the screenshot below:

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/002.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=3522edbd7956fe5ab02c3715d9f28110" alt="" width="2848" height="1076" data-path="images/labs/introduction-to-aws-step-functions/002.png" />

4. Under **Function code**:

   * **Replace** the existing code with the below python code.

```python theme={null}
import json
def lambda_handler(event, context):
# TODO: Implement your Lambda function logic here
return {
'statusCode': 200,
'body': json.dumps('You have successfully invoked the lambda function from Step Function.')
 }
```

5. Now save the code using by clicking on the **Deploy** button.

6. Now **copy** your lambda function **ARN** from the top right corner and place it in a text editor. This arn will be used later.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/003.jpg?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=68a0b858ee462f0ae3f66929be885798" alt="" width="1723" height="232" data-path="images/labs/introduction-to-aws-step-functions/003.jpg" />

#### Task 3: Create a State Machine in Step Function

1. Navigate to the **Services** menu at the top, then click on **Step Functions** in the **Application Integration** section.

2. Click on the **State machines** from the left navigation panel.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/004.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=b7882f686fc6e2f212777d9b457fb9a1" alt="" width="2752" height="978" data-path="images/labs/introduction-to-aws-step-functions/004.png" />

3. Click on **Create state machine** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/005.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=adc69ef9d22bafc314ec8e4e71e356ed" alt="" width="2358" height="608" data-path="images/labs/introduction-to-aws-step-functions/005.png" />

4. Select **Create from blank**. Give the **name** of your choice and Click on **Continue.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/006.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=c1297bce29f9ba58031aea984bd6e433" alt="" width="1763" height="674" data-path="images/labs/introduction-to-aws-step-functions/006.png" />

5. Click on **\{}Code.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/007.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=4ae14bfa24ab8d91e62c186f3728e0e9" alt="" width="784" height="251" data-path="images/labs/introduction-to-aws-step-functions/007.png" />

6. Definition : Replace the existing state machine JSON code with the below one.

\{

```python theme={null}
"Comment": "Sample State machine code to invoke a lambda function",
"StartAt": "invokeLambda",
"States": {
"invokeLambda": {
"Type": "Task",
"Resource": "<YOUR_FUNCTION_ARN>",
"End": true
 }
 }
}
```

7. Now replace the entire value of **Resource** key with the **lambda ARN** that you have copied and placed in the text edit.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/008.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=c7aa3410ad9f32e16c9b8fd9e6f96d13" alt="" width="1867" height="622" data-path="images/labs/introduction-to-aws-step-functions/008.png" />

8. Now on the right side the flow diagram will be as follows :

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/009.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=7776662b91115d65dc004506c9bcce47" alt="" width="547" height="396" data-path="images/labs/introduction-to-aws-step-functions/009.png" />

* **Note :** If this image is not displayed, please click the **refresh** button, to reload the diagram.

9. Now click on the **Config** button.
10. Specify details:

    * Name : Default ***MyStateMachine*** *(This name cannot be changed here) and Select* ***Standard*** *as Type.*

      <img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/010.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=be267169e2e0afda9efdf1fc8aafeb25" alt="" width="1482" height="668" data-path="images/labs/introduction-to-aws-step-functions/010.png" />
    * Permissions :

      * Execution role : select **Choose an existing role**
      * Existing roles : select **StepFunction\_lambda\_role-RANDOM\_NUMBER**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/011.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=a6d6ad8bd378147eca3795f9cf7a5416" alt="" width="1820" height="312" data-path="images/labs/introduction-to-aws-step-functions/011.png" />

* Leave everything as default.

11. Click on the **Create** button.

#### Task 4: Test the Step function

1. Click on the created state machine and select **Execute** button.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/012.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=608f23c969514867e47e423161184b5f" alt="" width="2368" height="500" data-path="images/labs/introduction-to-aws-step-functions/012.png" />

2. New execution :

* Enter an execution name : Enter ***SampleTest1***
* Input : leave as default.

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/013.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=bace7c8c992603f09c672e82dd72ddec" alt="" width="2674" height="1104" data-path="images/labs/introduction-to-aws-step-functions/013.png" />

3. Click on the **Start execution** button.

4. In the Graph inspector diagram, the colour of invokeLambda will become green (success) as shown in the image below.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/014.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=71a6a9d17f7b4054cfcdcfbf252da736" alt="" width="444" height="454" data-path="images/labs/introduction-to-aws-step-functions/014.png" />

5. Click on the **invokeLambda** step.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/015.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=7314b8ef33d049ba9edfae9dae595674" alt="" width="454" height="454" data-path="images/labs/introduction-to-aws-step-functions/015.png" />

6. You will be able to see the details below on the right side column.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/016.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=ec8f995ea9863221062ed5f1cb9bb34a" alt="" width="1054" height="460" data-path="images/labs/introduction-to-aws-step-functions/016.png" />

7. Now, click on the **Input/Output** tab. You will see the output from our lambda function.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/-IhT_VuqhvyVNtnn/images/labs/introduction-to-aws-step-functions/017.png?fit=max&auto=format&n=-IhT_VuqhvyVNtnn&q=85&s=f0980dd28d17b03eb37cc4d940a2e4df" alt="" width="2264" height="1164" data-path="images/labs/introduction-to-aws-step-functions/017.png" />

8. Once the lab steps are completed, please click on the **Validation** button on the left side panel.

> ##### Do You Know?
>
> Step Functions include built-in support for wait states, where you can pause the workflow execution for a specific duration, until a specified time, or until a specific event occurs.

### Completion and Conclusion

1. You have successfully created a Lambda function.
2. You have successfully created a state machine in a step function.
3. You have successfully tested the step function.

### End Lab

1. Sign out of AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End Lab** from the IP Lab Portal dashboard.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Create an AWS Lambda Function** — Check whether a Lambda Function is created or not
* **Check State Machine Exists** — Check whether a StepFunctions state machine is created.
* **Check State Machine Execution** — Check whether a StepFunctions state machine executes successfully.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.