Monday, February 14, 2022

Starting AWS Step Functions : Invoking API Gateway (REST Endpoints)

So, I am a Hard-Core Java/Java EE/Microservices Architect. My overall experience is ~17y. Recently, My organization required me to work on AWS Step Functions. This is my first foray into the world of AWS (Hands-On). Primarily, I have been a decision maker on this side, working closely with DevOps teams for decisions on EC2, ECR, ECS, EKS, Kubernetes (K8s), Docker and anything related to S3, RDS and thereof. 

Data Management in Microservices is usually one of the most important challenges that any Microservices Projects/Products have to face. The issues usually lie in the areas of:

  1. Data Consistency 
  2. Single Version of Truth
  3. Distributed Transactions
  4. Rollback & Retry Mechanisms
  5. Service Orchestration 

After the last ~4 years on Microservices Projects - Yet again I realized that Data Management in Microservices is the single most important topic along with Microservices Infrastructure, when organizations decide to adopt Microservices. As a solution, there are many known Microservices Design Patterns that come to the front. 
  1. Saga Design Pattern
  2. CQRS
  3. Event Sourcing
  4. 2-/n-Phase Commit   

The discussion of the above design patterns will be taken ahead in a separate article. This topic has been introduced in this manner as many of you might be facing a data consistency issue or will require business use case based manual rollback of transactions. Under such circumstances, the rollback is equivalent to a reversal of the transaction. It is also known as the Compensating Transaction Pattern. AWS Step Functions allows for the elegant implementation of the Business Use-Cases/Workflows. It allows for Workflow Flow Conditions, Handling Errors, Retry,  Timers,... We may also very easily implement the Compensating Transaction pattern using the AWS Step Functions. The most important part is that for an organization that is planning or already has its infrastructure on AWS, it allows for an all round seamless integration. 

We need to first understand the under the covers, every workflow is defined in the Amazon States Languages (ASL). "The Amazon States Language is a JSON-Based, Structured Language used to define your State Machine, a Collection of States, that can do work (Task States), determine which States to Transition to Next (Choice States), Stop an Execution with an Error  (Fail States), and so on." 

In this article, we will learnt to integrate AWS Step Functions with API Gateway. 

  1. AWS Console Access
  2. Free Tier Subscription
  3. IAM Rights Available*
  4. AWS Step Functions
  5. AWS -- API Gateway 

Steps to Create your First AWS Step Machine
01. Click on the AWS Search Box and Type 'Step Functions'

02. Click on the AWS Search Box and Type 'Step Functions' or Simply Click on 'Step Functions'

03. You may Click on 'Create State Machine' or Select one of the State Machine. We navigated to the below screen after we clicked on 'Create State Machine'.

4a. You may choose to either create a Step Function manually or simply click on 'Run a Sample Project'. Let us click on 'Run a Sample Project'. We will also select 'Make a Call to API Gateway'. 

4b. You may scroll down on the screen to see that the Amazon States Language and the Visual Workflow has already been Generated (Pre-Packaged).

05. We are all set to Deploy and Create the Sample State Machine. On the below screen, click on [Deploy Resources] to begin the creation of the API Gateway Deployment as well as the State Machine. 

06. The Next Screen will prompt us to try out the Execution of the State Machine. You may either use the Sample Input or give your own input values.

 Once you click on Start Execution, you will see a Success Screen as shown below.

08. You can also observe the Execution Event History just below the Graph Inspector.

Let us try to understand the most important parts of the Execution. The Step Input and Step Output for the workflow. You will understand that the output of one step becomes the input for the next step. Below is the Step Input for the step [Add Pet to Store]

10.The Step Output for the step [Add Pet to Store]

The Step Input for the step [Retrieve Pet Store Data]

The Step Output for the step [Retrieve Pet Store Data]

The Workflow Execution Input. (On the Topmost Section)

The Workflow Execution Output. (On the Topmost Section)

So, This is the way to create a Workflow using AWS Step Functions. This was the Sample Use-Case of Pet Store (In-Built) that connects to the REST Endpoints (Services) deployed on the API Gateway. This will be a good starting point for you to model your Business Workflows and Use-Cases. 

In the next article, I will show you how to modify this sample by creating our own REST Endpoints in API Gateway. Also, I will introduce the Workflow Studio. This tool eases the ability to model the workflows visually and also generates the Amazon States Language for the model. It provides an easy and intuitive way to model your Workflows.

Well, That was the first foray into the deep and vast Amazon Web Services (AWS) world for me - The Java/Java EE/Microservices Specialist. It also proved to me how easy AWS/Cloud has made for businesses and developers to model and implement every aspect - Architecture, Workflows, Deployments, Containers, Gateways, Databases, Integrations, Storage, [Anything]. I will still recommend the development on Java/Java EE for any requirement, excepting the deployment - Since it does not lock you onto any cloud provider or platform. 
But, The Rating for AWS Ecosystem : 


No comments: