Building serverless web application on AWS cloud

Published on: Sat, 25 Jul, 2020

By: Amit Rai

Serverless is buzzword now a days. All cloud provider companies including AWS offers a well-architected platform to build and run application and services without thinking about servers. Since most of the companies are moving toward service oriented architecture so recently popular, FaaS (Function as a Service) framework allow developer to build and upload any application on cloud without even thinking about provisioning, managing, installing  and scaling infrastructure. As per defination


"Serverless computing is a model where cloud provider manages the allocation and provisioning of infrastructure"


Serverless web application has its own benefits as compared to traditional one, as below

  1. No infrastrture administration required
  2. Scaling is flexible and automated
  3. High availability and fault-tolerant
  4. No payment for idle capacity


In this blog, we will go though a serverless web application architecture and we will see how can we build a serverless web application on AWS using managed services.


Application Architecture


                                    "Image from"


As depicted in architecture diagram application will use  Amplify Console, Amazon Cognito, amazon API Gateway, AWS Lambda and Amazon DynamoDB.


Deploying static web content  with Amplify Console


Your web application static content including HTML, CSS, JavaScript, images will be deployed and managed by AWS continues deployment server Amplify Console. Then application will be accessible using the public website URL provided by Amplify Console. There is no need to run any web servers to make web application available publicaly.


Amplify console will be integrated with your code repository in AWS CodeCommit or GitHub to continuous deploying application.


AWS Console > Amplify Console

Amplify Repository configuration


AWS Amplify Console easy to use platform to deploy really complicated static websites following a continuous integration and delivery model. It can show you a preview of your application as it would rendor on different platforms.


Amazon Cognito User Pool for user authorization


User accounts can be managed in Amazon Cognito user pool. Web application can have a user registration, email verification and user sign-in process. Application user can register himself after providing required attributes like email-id, password etc. Once registration request is submitted, Amazon Cognito will verify the user details by sending email or through console. Application frontend(JavaScript) function communicating with Amazon Cognito, authenticates using the Secure Remote Password protocol (SRP), and receives back a set of JSON Web Tokens (JWT). The JWTs contain claims about the identity of the user and can be used further to authenticate against the API with Amazon API Gateway.


AWS Console > Amazon Cognito

Create a user pool screenshot

User pools is used to host and manage users and allow us to authenticate them and manage their user information. Application website can provide a sign-in form to allow register user to signin to Amazon Cognito.



Amazon Lambda and DynamoDB (Backend service)

Application backend will be build using Lambda function and DynamoDB. Request from browser (frontend) will be handled by Lambda function and record the data in DynamoDB


AWS Console > DynamoDB

Create table screenshot

Creating IAM Role for Lamda Function


There should be an  IAM role associated with Lambda function. This role defines what other AWS services the function is allowed to interact with. For web application you can create an IAM role that grants your Lambda function permission to write logs to Amazon CloudWatch Logs and access to read and write to DynamoDB table.

Your backend code will be run in Lambda function in response to a HTTP request. Lambda function support most of the programming languages and platforms. You can choose any language to create backend logic. Later, Lambda function will be connected to  API in order to create a fully functional backend for your web application.


AWS Console > Lambda

Create Lambda function screenshot


Lambda is a serverless FaaS (functions as a service) AWS platform that doesn't require managing servers to run any application. Function can be assigned a role and trigger point and then can interface with anything from databases,  to any other services on the internet or internal VPC.


Amazon API Gateway

API Gateway is a fully managed AWS service to create, publish, maintain, monitor, and secure scalable APIs. The API can easily integrated with Cognito for authorization and Lambda function for backend to create completely serverless application.


AWS Console > API Gateway

Create API screenshot


After integration of API Gateway (RESTful API)  with Lambda function that is created to run backend. You have to update the website to use the API endpoint so that frontend request can processed by lambda and information is saved in the DynamoDB table.


This was a very high level overview of AWS managed services those can be used building a serverless web application. A developer can leverage these services to build applications and can save a lot of time and money.