AWS Step Functions - Hands On Demo

Create First Lambda Function

 

  1. Select "Author from scratch"
  2. Function name: FirstLambdaFunction
  3. Runtime: Python 3.12
  4. Keep other values as default.
  5. Paste the below code as function code.
import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from First Lambda!')
    }

Create Second Lambda Function

 

  1. Select "Author from scratch"
  2. Function name: SecondLambdaFunction
  3. Runtime: Python 3.12
  4. Keep other values as default.
  5. Paste the below code as function code.
import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Second Lambda!')
    }

Create a State Machine in AWS Step Functions

  1. Open Step Functions Console: Navigate to the Step Functions console in the AWS Management Console.
  2. Create State Machine: Click "Create state machine".
  3. Define State Machine: Choose "Code" and paste the following Amazon States Language (ASL) definition.
  4. Make sure to replace the ARN of the First and Second Lambda Function.
{
  "Comment": "A state machine that calls two Lambda functions in sequence",
  "StartAt": "FirstFunction",
  "States": {
    "FirstFunction": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:211125437318:function:FirstLambdaFunction",
      "Next": "SecondFunction"
    },
    "SecondFunction": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:211125437318:function:SecondLambdaFunction",
      "End": true
    }
  }
}

Start and Monitor Execution

  1. Start Execution: With the updated state machine, click "Start execution". Optionally, provide JSON input, though it's not required for this example.
  2. Monitor the Workflow: Watch as the state machine executes, first invoking FirstLambdaFunction and then SecondLambdaFunction. The execution detail page shows the progress and results of each step.

Available Templates - 1

Available Templates - 2

Thanks

for

Watching

Clean Up

 

  1. Delete the State Machine.
  2. Delete the Lambda Functions.

AWS Step Functions - Hands On Demo

By Deepak Dubey

AWS Step Functions - Hands On Demo

AWS Step Functions - Hands On Demo

  • 65