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.
-
Login to the AWS Console and select Ireland as the region.
-
Goto the Lambda Console, click on the Functions menu in the left and then click on the Create function button.
-
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.
-
The function is created in no time. Next, you goto the Function code area and update the code with the code provided below.
import json def lambda_handler(event, context): x = event["Input"] return { 'statusCode': 200, 'body': json.dumps("You called the lambda function with parameter - " + x) }
`
-
In the code above, the Lambda function receives the input and then simply echoes back the input in the output.
-
Click on the Deploy button to save and upload the lambda function code.
-
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.
-
Goto the Step Functions Console, click on the State machines menu in the left and then click on the Create state machine button.
-
On the next screen, select Author with code snippets option. Select Express for the type.
-
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.
{ "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 } } }
`
-
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.
-
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.
-
The workflow is created in no time. Once the workflow is created, on the workflow detail page, click on the Start execution button.
-
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.
{ "data": "input1" }
`
-
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.
-
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).
-
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.
-
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.