Creating a serverless workflow using AWS Lambda and Step Functions

Creating a serverless workflow using AWS Lambda and Step Functions

Introduction

In this article, I detail how I used AWS Step Functions to design and run a serverless workflow that orchestrates multiple AWS Lambda functions.

Here, I create a serverless application to automate handling of support tickets in a call center. While you could have one Lambda function call the other, it may be challenging to manage all of these connections as the call center application becomes more sophisticated. Plus, any change in the flow of the application will require changes in multiple places, and it could lead to writing the same code over and over again.

Before I go on, I will like to briefly introduce these AWS services so you can have a basic understanding of how they work.

AWS Lambda:

AWS Lambda is a serverless compute service that allows you to focus on your code without having to worry about provisioning and managing servers. It allows you to bring your own code in any language as it supports Java, Go, PowerShell, Node.js, C#, Python, and Ruby code, and also makes provision to allow use of additional programming languages to author your functions with a Runtime API. Since AWS Lambda is managed by AWS on your behalf, highly availability, fault tolerance and auto-scaling are guaranteed as resources are provisioned to respond to demand depending on the amount of requests received and compute capacity across multiple Availability Zones (AZs) in each AWS Region is done to losing data in case of data centre failures.

AWS Step Functions:

AWS Step Functions is a serverless orchestration service for modern applications. Orchestration centrally manages a workflow by breaking it into multiple steps, adding flow logic, and tracking the inputs and outputs between the steps. As your applications execute, Step Functions maintains application state, tracking exactly which workflow step your application is in, and stores an event log of data that is passed between application components. That means that if networks fail or components hang, your application can pick up right where it left off.

Application development is faster and more intuitive with Step Functions, because you can define and manage the workflow of your application independently from its business logic. Making changes to one does not affect the other. You can easily update and modify workflows in one place, without having to struggle with managing, monitoring and maintaining multiple point-to-point integrations. Step Functions frees your functions and containers from excess code, so your applications are faster to write, more resilient, and easier to maintain. aws.amazon.com/step-functions/features

Implementation:

Step 1: Create an AWS Identity and Access Management (IAM) role

AWS IAM is a web service that helps you securely control access to AWS resources. You use it to control who has access to resources created on your AWS account. An IAM role that allows Step Functions to access AWS Lambda was created. An AWS managed policy is attached which allows step functions access AWS Lambda. image.png

Step 2: Create a state machine and serverless workflow

A workflow that describes how the support tickets are handled in the call center was defined. Workflows describe a process as a series of discrete tasks that can be repeated several times. Then, the workflow was designed in AWS Step Functions. The workflow calls one AWS Lambda function to create a support case, invokes another function to assign the case to a support representative for resolution, and so on. It also passes data between Lambda functions to track the status of the support case as it's being worked on.

image.png

image.png

After this is done, the state machine is now ready to execute and the workflow was executed to see how it would work.

image.png

image.png

This terminates the workflow after the "Escalate Case" state. Several workflows can be implemented depending on what the desired result is but this shows how several lambda functions can be made to work together using AWS Step Functions.

Thanks for making it this far! Comments are greatly appreciated.

If you want to get hands-on with this, visit aws.amazon.com/getting-started/hands-on/cre..

[Cover Image](Image by rawpixel.com on Freepik)