Important Note: You will create AWS resources during the exercise which will incur cost in your AWS account. It is recommended to clean-up the resources as soon as you finish the exercise to minimize the cost.

Using AWS Step Functions Express Workflows

Express Workflows are a new type of AWS Step Functions workflow which can run in synchronous manner. Express Workflows is suitable for high-volume event processing workloads such as IoT data ingestion, streaming data processing and transformation, and high-volume microservices orchestration.

In this exercise, you create and run a Step Functions Express Workflow.

The AWS Resource consumption for the exercise falls under AWS Free Tier.

Step1: Pre-Requisite


You need to have an AWS account with administrative access to complete the exercise. If you don’t have an AWS account, kindly use the link to create free trial account for AWS.

Step2: Create Lambda Function


You create Lambda function which is called by the Step Functions Workflow.

  1. Login to the AWS Console and select Ireland as the region.

  2. Goto the Lambda Console, click on the Functions menu in the left and then click on the Create function button.

    Lambda

  3. On the next screen, select Author from scratch as the option. Type in dojofunction as the name. Select Python 3.8 as the runtime. Select Create a new role with basic Lambda permissions as the option for the permissions. Finally click on the Create function button.

    Lambda

  4. The function is created in no time. Next, you goto the Function code area and update the code with the code provided below.

    Lambda

    import json
    
    def lambda_handler(event, context):
           
        x = event["Input"]
           
        return {
            'statusCode': 200,
            'body': json.dumps("You called the lambda function with parameter - " + x)
        }
    

    `

  5. In the code above, the Lambda function receives the input and then simply echoes back the input in the output.

  6. Click on the Deploy button to save and upload the lambda function code.

    Lambda

  7. The Lambda function is ready. Make note of the ARN for the Lambda function as you need it later when configuring Step Function Workflow. You now configure Step Functions Express Workflow which makes call to the Lambda function.

Step3: Create and Run Express Workflow


You configure Step Functions Express Workflow which makes call to the Lambda function.

  1. Goto the Step Functions Console, click on the State machines menu in the left and then click on the Create state machine button.

    Step Functions

  2. On the next screen, select Author with code snippets option. Select Express for the type.

    Step Functions

  3. On the same screen, copy-paste the json definition below in the definition field. Replace {{LAMBDA_ARN}} with ARN of the Lambda function you made note of in the previous step.

    Step Functions

    {
      "Comment": "Calling Lambda Function",
      "StartAt": "CallLambdaFunction",
      "States": {
        "CallLambdaFunction": {
          "Type": "Task",
          "Resource": "arn:aws:states:::lambda:invoke",
          "Parameters": {
            "FunctionName": "{{LAMBDA_ARN}}",
            "Payload": {
              "Input.$": "$.data"
            }
          },
          "End": true
        }
      }
    }
    

    `

  4. In the workflow definition above, the workflow is making call to the Lambda function. The payload for the Lambda function is taken from the data element from the input parameter json document for the workflow. Click on the Next button.

  5. On the next screen, type in dojoworkflow as the workflow name. Select Create new role for the permissions. Keep rest of the configuration to the default and click on the Create state machine button in the bottom of the screen.

    Step Functions

  6. The workflow is created in no time. Once the workflow is created, on the workflow detail page, click on the Start execution button.

    Step Functions

  7. On the next screen, select Synchronous for the type. Copy-paste the json document below for the input to the workflow. Click on the Start execution button.

    Step Functions

    {
        "data": "input1"
    }
    

    `

  8. The workflow works in synchronous manner. It will take input, run the workflow logic which is calling Lambda function with the input and finally show the response back in synchronous execution. You can see successful execution of the workflow. Click on the Details link.

    Step Functions

  9. On the details page, you can see the input passed as well as the response provided back by the workflow (which actually is the response from the Lambda function).

    Step Functions

  10. You run the workflow from the console. You can also run workflow through another Lambda call or based on some AWS Services Event or from an API in API Gateway. You can build microservices using the express workflow.

  11. This finishes the exercise. In the next step, you clean-up the resources so that you don’t incur any cost post the exercise.

Step4: Clean up


Delete dojofunction Lambda Function.

Delete dojoworkflow State Machine Workflow.

Thanks and hope you enjoyed the exercise.


Back to the Exercises