AWS Project- Building a Serverless Architecture on AWS Using the Serverless Framework
Get started with Serverless Framework’s open-source CLI and Amazon Web Services in minutes.
Table of contents
- Introduction
- Project Overview
- Setting Up Serverless Framework With AWS
- Installation
- Step 1: Install npm (if not installed):
- Step 2: Install Node.js version 16.0.0
- Step 3: Install Node Version Manager (NVM)
- Step4 : Check Node.js and npm versions
- Step5 :Install Serverless Globally
- Step 7: Verify Serverless Installation
- Step 8: Initialize Serverless Project
- Step 9: Navigate to Project Directory
- Step 10: Edit handler.py in Vim
- Step 11: Edit serverless.yml in Vim
- Step 9: Create AWS Credential:
- Step 10: Create AWS Provider on serverless Framework:
- Step 11: Let's Deploy our Serverless Project:
- Step 12: Integration with Serverless Framework Observability
- Step 13: Access the Serverless Dashboard
- Step 39: Review Deployed Functions
- Step 14: Access the Deployed Endpoint
- Conclusion
Introduction
In today's rapidly evolving technology landscape, serverless architecture has become a go-to choice for building scalable and cost-effective applications. In this blog post, we will walk through the process of creating a serverless project on AWS using the Serverless Framework. Our project will involve the use of various AWS services such as EC2, S3, IAM, DynamoDB, Lambda, API Gateway, CloudWatch, and CloudFormation to build a robust and secure infrastructure.
Project Overview
Our serverless project will consist of the following components:
EC2 Instance: Acting as the headquarters to manage and operate the entire infrastructure.
S3 Bucket: Hosting the code for our Lambda functions.
IAM (Identity and Access Management): Ensuring secure access to AWS resources.
DynamoDB: A NoSQL database for storing and retrieving data.
Lambda Functions: Responsible for inserting data into DynamoDB and handling other business logic.
API Gateway: Serving as the entry point for external requests to our serverless architecture.
CloudWatch: Logging errors and monitoring our Lambda functions.
Setting Up Serverless Framework With AWS
Get started with Serverless Framework’s open-source CLI and Amazon Web Services in minutes.
Installation
Step 1: Install npm (if not installed):
ubuntu@ip-172-31-44-217:~$ sudo apt install npm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
Install npm if it is not already installed.
Step 2: Install Node.js version 16.0.0
ubuntu@ip-172-31-44-217:~$ nvm install 16.0.0
Downloading and installing node v16.0.0...
Downloading https://nodejs.org/dist/v16.0.0/node-v16.0.0-linux-x64.tar.xz...
####################################################################################################################### 100.0%Computing checksum with sha256sum
Checksums matched!
Now using node v16.0.0 (npm v7.10.0)
Creating default alias: default -> 16.0.0 (-> v16.0.0)
Use NVM to install Node.js version 16.0.0.
Step 3: Install Node Version Manager (NVM)
ubuntu@ip-172-31-44-217:~$ sudo apt install curl
ubuntu@ip-172-31-44-217:~$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
ubuntu@ip-172-31-44-217:~$ source ~/.bashrc
ubuntu@ip-172-31-3-31:~$ nvm install 16.0.0
Downloading and installing node v16.0.0...
Downloading https://nodejs.org/dist/v16.0.0/node-v16.0.0-linux-x64.tar.xz...
####################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.0.0 (npm v7.10.0)
Creating default alias: default -> 16.0.0 (-> v16.0.0)
Install NVM to manage multiple Node.js versions.
Step4 : Check Node.js and npm versions
ubuntu@ip-172-31-44-217:~$ node -v
v16.0.0
ubuntu@ip-172-31-44-217:~$ npm -v
7.10.0
Verify that Node.js and npm are installed and display the installed versions.
Step5 :Install Serverless Globally
Install the Serverless Framework globally using npm.
If you don’t already have Node.js on your machine, install it first. If you don't want to install Node or NPM, you can install Serverless as a standalone binary
Step 7: Verify Serverless Installation
- Ensure that Serverless is successfully installed and accessible by running the
serverless
command.
Step 8: Initialize Serverless Project
Create a new Serverless project using the interactive prompts. Choose "AWS - Python - HTTP API" and name it "aws-python-http-api-project".
Step 9: Navigate to Project Directory
ubuntu@ip-172-31-0-5:~$ cd aws-python-http-api-project/
ubuntu@ip-172-31-0-5:~/aws-python-http-api-project$ ls
README.md handler.py serverless.yml
Change into the directory of the newly created Serverless project.
Step 10: Edit handler.py in Vim
Make modifications to the Python code in the handler.py file using the Vim text editor.
Step 11: Edit serverless.yml in Vim
Make modifications to the Serverless Framework configuration in the serverless.yml file using the Vim text editor.
Step 9: Create AWS Credential:
-
ubuntu@ip-172-31-3-31:~/aws-python-http-api-project$ aws configure AWS Access Key ID [****************MSIR]: AWS Secret Access Key [****************x3rT]: Default region name [None]: Default output format [None]:
Step 10: Create AWS Provider on serverless Framework:
Create AWS Provider on serverless Framework and make this as a default:
Step 11: Let's Deploy our Serverless Project:
-
Execute the serverless deploy command to deploy your Serverless project to the specified AWS region (in this case, ap-south-1) and stage (dev).
Step 12: Integration with Serverless Framework Observability
Upon successful deployment, Serverless Framework Observability is integrated into your AWS account. This enhances monitoring and observability of your Serverless application.
Step 13: Access the Serverless Dashboard
Visit the Serverless Framework Dashboard to get a comprehensive overview of your deployed service.
Step 39: Review Deployed Functions
Check the details of the deployed functions, including their names and sizes.
Function Name: hello
Function Size: 85 kB
Step 14: Access the Deployed Endpoint
Use the provided endpoint URL to access your deployed Serverless function.
Conclusion
This blog post covered the end-to-end process of creating, configuring, and deploying a serverless project on AWS using the Serverless Framework. The integration of various AWS services ensures a scalable and robust infrastructure. The provided steps and commands, along with accompanying screenshots, should serve as a comprehensive guide for readers to replicate and extend this project.