Serverless Arcjitecture with AWS

Serverless Architectures with AWS

Any application that you create or use is multi-tiered because there exists the User Interface, the Business Logic, and the Database. Today we use microservices, which means you don’t develop a monolithic application. Whenever you create an application, you break it down into multiple pieces and code for individual pieces. Its major advantage is that even when the application is executing, you can make an update. 

But how do we build Serverless Architecture with AWS?

Whizlabs, on 2nd December 2021, conducted a Webinar on “Serverless Architectures with AWS” with Mr. Bharath S.

Bharath is a Cloud/DevOps Engineer at AMM offering for Deloitte, helping clients to adopt and accelerate their Cloud Journey. He is also helping them in the digital transformation of their workloads and environment, and making them cloud-native ready. His areas of expertise are Cloud Product Management, Digital Transformation, Cloud Migration & Modernization, and end-to-end Digital Transformation.

The main objective of this session is to help developers leverage the Amazon Gateway and AWS Lambda, and other services to reduce the development and operational cycles required to create and manage multi-tier applications.

Three Tier Architecture Overview

Three Tier Architecture Overview

Any application built is generally multi-layer or n tier. The most popular application formulation pattern is:

  • Presentation Tier: This is the component of the application that directly interacts with the user. For example- Web Page, Mobile app Ui, and more.

When we go to a web page, there exists a clickable button containing a function that gets executed when you click on it.

  • Logic Tier: This tier is the brain of the application. It contains the code required to translate user actions into application functionality, for instance, CRUD Database Operations, Data Processing, etc.
  • Data Tier: This tier refers to the Storage Media, i.e. Database, Object Storage, Cache, File System, etc. Object storage is a place where you save audio, video, or structured data. Caching is used to reduce latency.

For example, the application is in the US and the customer is in Japan, due to distance the latency will increase but with the help of cache, only the first user will face the delay and the rest of the users can use the cached copy, resulting in reduced latency.

Serverless Logic Tier:

This is the place where the Amazon API Gateway and AWS Lambda are most impactful as compared to the traditional server-based application.

The features of these two servers allow us to build a serverless application that is highly available, has low latency, and is scalable and secure.

In a traditional model, the application would require thousands of servers. However, by leveraging Amazon API Gateway and AWS Lambda, you do not have to take the responsibility of server management.

Why is this concept the future of computing?

  • You do not have to worry about choosing the Operating System.
  • Reduces the risk of overpricing due to overprovisioning.
  • Reduces the risk of performance due to underprovisioning.

API Gateway is the mechanism to deploy, monitor, and secure the API.

API: API stands for Application Programming Interface. It allows two software to talk to each other. Each API exposes its endpoints as URL, through that URL you can interact. It also supports improved API performance via Caching and Content Delivery.

What is AWS Lambda?

AWS Lambda

AWS Lambda is a serverless compute service that allows you to run arbitrary code functions in any of the supported languages. For example, Node.js, Python, Ruby, JAVA, Go, .Net, and their versions. Amazon nowadays is adding a lot of Javascript Framework languages to write these arbitrary functions.

Read our detailed blog on What is AWS Lambda.

Function: A function is a piece of code that does an action without provisioning, managing, or scaling servers. For instance, if you need an image to be uploaded, you have to write a function.

Popular use cases of AWS Lambda revolve around event-driven data processing workflows, such as processing the files in S3. AWS Lambda gets triggered through an event, which could be manual or automated.

When used in conjunction with API Gateway, AWS Lambda performs the function of a web server. It executes the code and responds to the client’s HTTP request. Amazon API Gateway acts as the front door for the logic tier and AWS Lambda executes the application code. This could be through an HTTP request or an event that you have created on the Cloud.

AWS Lambda requires you to write code functions called Handlers, a terminology coined by AWS, which will execute when triggered by an event. The event might be an HTTP request or a manual or automated event that is created by integrating the various servers of AWS. To use AWS Lambda with Amazon API Gateway, you can configure API Gateway to trigger handler functions, when an HTTP request to your API is made.

In a serverless multi-tier architecture, each of the APIs that you create in Amazon API Gateway will integrate with Lambda. So, when you create APIs, they will give you an HTTPS endpoint, which is a URL, so as soon as you trigger the HTTP request, the Lambda gets generated that executes the business logic.

Lambda Architecture Pattern inside a VPC

The user sends an HTTP request to the API Gateway. The HTTP request will act as an event for AWS Lambda to allow it to execute the process. Normally, when you deploy a Lambda function, it is executed as per the permissions defined by its assigned IM role and is able to reach the internet-facing endpoints. As the core of the logic tier, this lambda is a component directly integrated with the data tier. If the data tier contains sensitive business or user information, then it becomes necessary to ensure that the data tier is not exposed to the open internet, and is completely isolated, that is why we put the data tier completely inside the private VPC. For a lambda function to be able to access resources that you cannot expose publicly like your private database instance, you can place the lambda function inside the private VPC, so that the lambda function could be accessed from a database instance.

Amazon API Gateway

The Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale.

Clients, that is, the presentation tier integrate with the APIs exposed via API Gateway using standard HTTP requests.

Features of the Amazon API Gateway:

  • Integration with AWS Lambda
  • Proxy Integrations
  • Non-Proxy Integrations
  • Stable API performance across regions
  • Reduced overhead with built-in-features
  • Prioritized API Security

API Authorization

There exist three general methods to add authorization to an API in Amazon API Gateway:

  1. IAM roles and policies: Here we create roles and policies to make sure that we narrow down the access and it’s being properly executed. 
  2. Amazon Cognito User Pools: Here, clients sign in via Amazon Cognito User Pools and obtain tokens.
  3. Custom Authoriser: Defines a Lambda function that implements a custom authorisation scheme that uses a token strategy.

Serverless and Non-Serverless Data Layer options that can be integrated with Amazon API Gateway and Lambda:

  • Serverless Data Storage Options
  1. Amazon S3
  2. Amazon Aurora
  3. Amazon DynamoDB
  4. Amazon Timestream
  5. Amazon Quantum Ledger Database(Amazon QLDB)
  • Non-Serverless Data Storage Options
  1. Amazon RDS
  2. Amazon Redshift
  3. Amazon ElastiCache
  4. Amazon Neptune
  5. Amazon DocumentDB

Presentation Layer

The presentation layer is responsible for interacting with the logic tier via the API Gateway REST endpoints exposed over the internet.

Any HTTPS capable client or device can communicate with these endpoints, giving the presentation layer the flexibility to take multiple forms like desktop applications, mobile apps, Web Pages, and so on.

Depending on the requirements, the presentation layer may use the following AWS Serverless offerings:

  • Amazon Cognito
  • Amazon S3 with Amazon CloudFront

Sample Architectural Patterns

Mobile BackendSingle Page ApplicationMicroservices with LambdaMicroservices with Lambda

Serverless Case StudiesServerless Case Studies

The Coca-Cola Company: This company has used serverless architecture and have reduced their cost by 70%. As per the traditional server system, the vending machines used to have an integrated communication system with the Coca-Cola company headquarters, and that is how they know if a particular machine is low on beverages.

But now, by using the serverless architecture, they have been able to reduce their cost from $4500 per year to $1300 per year.

To learn more about this interesting cost-saving that happened in the Coca-Cola company and get a hands-on experience in serverless architecture, please watch the complete webinar recording Where Mr. Bharath S explains everything in detail, by following the below link:

About Abilesh Premkumar

Abilesh holds a Master's degree in Information technology and Master of Philosophy Degree in Computer Science and did his Research on Information security via Collaborative Inference Detection. Also, received an Honorary Doctorate from UNO recognized organization. He contributes to Cloud research and supports building cloud computing tools.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top