Intro to web app using AWS Serverless Architecture
Tags: aws, serverless, webdev, beginners
Published: 2021-04-17 13:54:26

Serverless architecture comprises a group of technologies working together as a single unit to deliver a solution. In this write-up, let’s review the involved technologies along with their high level purpose to build a web application.


![High level serverless architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b94wkskjehhaahhsisko.png)


<h3>Backend</h3>

Backend is a stand-alone service comprising three main components - Data store, Lambda functions used as a compute service and API Gateway acting as a main backend interface.

<h4>Data Store / Database</h4>
Aurora Serverless (PostgreSQL) is one of the options. There are few other serverless database options available to choose from. Data store choice purely depends on the type of data stored within the application.
  
<h4>Lambda Functions</h4> 
Lambda functions with Python could be used on the backend. AWS Lambda supports many other options such as Node.js, Java, .NET Core, PHP.

<h4>API Gateway</h4>
API Gateway serves as a gatekeeper to the backend service. API endpoints can be secured and served through the API Gateway. API Gateway leverages lambda functions to perform necessary data processing to serve requests made to the API endpoint. Frontend applications or any other service requiring data can call these API endpoints with required security token to obtain necessary data. 


<h3>Frontend</h3> 
Frontend framework such as Angular, Vue, React or any other framework could be used to build the frontend website. During deployment, front-end code is built and deployed to **AWS CloudFront** CDN and served to the end users’ browsers upon request. 


<h3>Security</h3>
**AWS Cognito** is an Amazon authentication and authorization service. This service also has support for SAML / OAuth2 / Open ID authentication through major Identify providers such as Facebook, Google, Okta.  

<h3>Supporting Services</h3>
Besides above mentioned core services, there are many other supporting services involved in the serverless application architecture. Let’s review the purpose of these supporting services.

<h4>Serverless Framework</h4> 
Serverless Framework helps develop and deploy serverless applications along with the required infrastructure resources they require. It's a CLI that offers structure, automation and best practices out-of-the-box and helps build sophisticated, event-driven, serverless architecture applications. Framework itself is built with Node.js but it can support multiple languages (Node.js, Python, Java, and more). This framework is cloud-agnostic meaning one can use this framework to develop serverless applications for any cloud provider. 

AWS Serverless Application Model is an alternative option to serverless framework but it is specific to AWS.

<h4>AWS CloudFormation</h4>
AWS CloudFormation gives an easy way to model a collection of related AWS resources, provision them quickly and consistently across different environments, and manage them throughout their life cycles, by treating infrastructure as code. Serverless framework’s configuration files describe all of the services that need to be provisioned for a given application.

<h4>AWS S3</h4> 
Simple Storage Service(S3) can be used as an intermediate storage for transferring and processing data from external systems. S3 can also be used for storing artifacts during the build and deployment process. 

<h4>IAM</h4>
Identity and Access Management Service is one of the important services in this solution. This service is mainly used for providing granular access permissions among various services used within the AWS serverless environment.

<h4>Route 53</h4>
This service is used for domain registration so deployed applications could be accessed using a user-friendly URL.

<h4>AWS CloudWatch</h4>
AWS CloudWatch is a logging service used by other services to log messages within the serverless solution. Messages logged in the service can be used for setting up alerts in case there are errors/issues within the application.   

<h4>Source Control</h4> 
**AWS CodeCommit** is AWS provided solution for source control. Other third party source control solutions such as **Github** can also be used for source code management.

<h4>Code Pipeline</h4>
This AWS solution enables automation of continuous build and deployment of applications.

<h4>Amazon SNS</h4>
Simple Notification Service used for event messaging. Events could be notified to multiple interested systems enabling microservices / distributed processing.

<h4>Amazon SQS</h4>
Simple Queue Service is a messaging service used for processing events sequentially. This service can scale well and also has facilities for guaranteed delivery of sequenced messages.

<h4>AWS Systems Manager</h4>
Systems Manager Parameter Store is used for application’s configuration and secrets management.

<h4>VPC</h4>
All of the services configured for the serverless solution would be deployed within the application’s secure Virtual Private Cloud environment. VPC should be configured properly to avoid security holes.

<h3>Benefits</h3>

Here are some of the benefits of using serverless architecture:

* This architecture scales well from few users to thousands of concurrent users.
* As there are no dedicated hardware resources provisioned as part of this solution, there is no infrastructure cost around server maintenance and upgrades.
* Also, the services involved in this solution are charged based on usage. This solution could be cost effective if configured properly.   

<h3>Further Learning</h3>

https://aws.amazon.com/getting-started/deep-dive-serverless/
https://www.serverless.com/learn/