Lambda Function on AWS (Part 1)

Abdullah Ayad
3 min readOct 11, 2023

Explaining what is AWS Step Functions

AWS Step Functions is a web service that enables you to coordinate the components of distributed applications and microservices using visual workflows. You build applications from individual components that each perform a discrete function, or task, allowing you to scale and change applications quickly. Step Functions provides a reliable way to coordinate components and step through the functions of your application. Step Functions provides a graphical console for visualizing the components of your application as a series of steps. It automatically triggers and tracks each step and retries when there are errors, so your application executes in order as expected, every time. Step Functions logs the state of each step, so when things do go wrong, you can diagnose and debug problems quickly.

Step Functions manages the operations and underlying infrastructure for you to ensure your application is available at any scale.

With Step Functions, you are able to easily coordinate complex processes composed of different tasks. For example, if you have an image and you need to convert it into multiple formats, scale it in different resolutions, and analyze it with Amazon Rekognition, you can split this process into single and atomic tasks with Lambda Functions and execute them simultaneously. After that, you can have another function that checks the result of this process.
Without using this service you have to coordinate each Lambda Function yourself and manage every kind of error in all steps of this complex process.

In this screenshot, you can see a graph that demonstrates the example above.

Once started, you can see that four tasks are executed simultaneously, then the result is analyzed before the Step Function completes.

Explaining what you are going to build with Step Functions

AWS Step Functions is a useful service for breaking down complex processes into smaller and easier tasks. In this lab, you have a real-world-scenario example in which you will build a solution using AWS Step Functions. You will write small and atomic, reusable Lambda Functions. These can be reused in several places, for example:

in different flows
as an endpoint behind an API Gateway
as a single function in response to an event
The details of your specific scenario are as follows:

CloudAcademy has already developed your game using Lambda, DynamoDB and other AWS services. What is missing are several housekeeping tasks for when a user completes a level or the entire game.

This process seems easy but consists of the following different tasks:

Generate a report for the last completed level
If the user ends a level, update the CompletedLevel table
If the user ends the entire game, update the CompletedGame table
Log a metric to CloudWatch
To accomplish this, you need to create a state machine. All state machines in AWS are defined using the Amazon States language. This is a JSON-based language used to describe state machines declaratively.

In the AWS Console, you can build a workflow and visualize it through a flowchart. The screenshot below represents your flow:

The JSON necessary to create this chart is shown below and you will analyze it in greater detail in the following steps:

As you can see, this is not a linear flow. Thankfully, AWS Step Functions provides different types of steps. This is an introductory lab on this service so you will not carry out every step type. You will, however, include the parallel and conditional step types in this lesson.

Creating Parallel Step Type

See part 2 from here

GitHub
LinkedIn
Facebook
Dev

--

--

Abdullah Ayad

Machine Learning and AI(NLP & Computer Vision) Engineer, AWS Community Builder, Kaggle Expert