Serverless Orchestration using AWS Step Functions

Shehreen Khan
5 min readJun 9, 2021

--

In this article, we will see what are AWS Step Functions and How can we use them to design a serverless workflow with AWS Lambda Functions.

What is Step Function?

AWS Step Function is a serverless orchestration service that combines other AWS services to build business-critical applications. Step Functions manages sequencing, error handling, retry logic, state, and provides a graphical console to arrange and visualize the series of event-driven steps of your application through its graphical console.

This makes it simple to build and run multi-step applications. Step Functions automatically triggers and tracks each step, and retries when there are errors, so your application executes in order.

What is AWS Lambda Function?

AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers, creating workload-aware cluster scaling logic, maintaining event integrations, or managing runtimes.

Lambda is a solution to build microservices using the serverless architecture paradigm. Instead of building out a server from scratch, spending time and resources on hosting and configuration, Lambda Functions provides a Function As a Service (FaaS), which allows you to quickly and easily write server-side code in the cloud.

It’s much easier to explore and understand concepts around service coordination using some use-cases . So in this article, we’ll discuss a very simple use-case of Course Enrollment System using these 2 services.

In the picture below, we can see how an orchestration-based approach for our course enrollment system could work. We’ll use orchestration to manage our processing workflow, the application will check the user’s name, email-Id, and payment status. After checking the details we will validate it via the database records, If the details are correct, We will enroll the user in the course else the enrollment will be canceled.

Workflow Design

So now we’ve covered enough background!! It’s time to get hands-on and learn by building it.

  1. Search for Step Functions on the AWS console and create a new State machine of the Standard type.
State Machine

2. Define our workflow design using this code which will help us to design our enrollment system. On the RHS, We can view the actual flow of our code and change it accordingly to get the exact results.

Workflow Code

3. On the next page, Give the name of our State machine and Create a new role with lambda:InvokeFunction permission for attaching it to our state machine So that it can invoke our lambdas without any errors. Once this is done, click on create.

4. Now we need to create our lambda functions to integrate them with our Step function flow. We will create four Lambdas each for checking the name, email-id, payment status, and validating these details. The input to below 3 lambdas will be given from the Step Functions, i.e name, email-id, and the payment status.

Check-Name Lambda
Check-Email Lambda
Check-Payment Lambda

5. Validate-Details Lambda function will receive the input from the above 3 lambdas via the step function workflow. I have created 3 dummy lists as database records to validate the details we received, Once the details are verified, We will return the result of course enrollment.

All these lambda codes are available here!!

Validate-Details Lambda

6. Now our entire workflow is ready and we can start the execution of our step functions state machine. Go to our state machine console, and click on Start execution. Give the below JSON as input and start the execution.

State Machine Input

7. Once the execution is successfully completed, We will get the desired graph and the success message of our workflow.

State Machine Workflow

8. Now let’s check what’s the input and the output that was received by our state machine blocks. Below is the input and output received by our CheckEmail state.

Step Input of LookUpEmail
Step Output of LookUpEmail

9. The next state i.e the VaildateDetails state would have received the input as all the 3 fields such as name, email-id, payment status, and accordingly it would have checked it in the database to give the enrollment result.

Step Input of ValidateDetails
Step Output of ValidateDetails

With this, We have successfully completed setting up an automated process and understanding it’s flow. Here, We implemented a very simple architecture to understand it but AWS Step Functions are used in business scenarios to track the resolution of issues raised by the customers, In Sequence batch processing, Sequence machine learning in workflows, and many such use-cases.

I hope you have enjoyed it. Please do not hesitate to give feedback, share your own lessons, or simply like it :)

--

--

Shehreen Khan
Shehreen Khan

Written by Shehreen Khan

Framework Engineer at Quantiphi Analytics | AWS | GCP | Azure

No responses yet