Introduction
Building and deploying serverless applications can be an exhilarating experience. In this comprehensive guide, we'll walk through the process of creating an EC2 instance, installing Node.js and npm, creating a new serverless project, setting up AWS credentials, and deploying a serverless application. Additionally, we'll explore testing, monitoring, and the powerful world of CI/CD (Continuous Integration/Continuous Deployment). Let's dive right in! ๐ ๏ธ๐จโ๐ป
Prerequisites
Before we start, ensure you have the following prerequisites:
๐ง EC2 Instance:
- Access to an AWS EC2 instance to run your serverless project.
๐ฆ Node.js and npm:
- Install Node.js version 20 and npm version 10 on your EC2 instance.
๐ผ Serverless Framework:
- Install the Serverless Framework globally:
npm install -g serverless
.
๐ AWS Credentials:
- AWS access and secret keys with admin access to connect with your AWS account.
๐ Authentication Access:
- Be prepared to provide authentication access by typing "yes" when prompted.
Creating a Serverless Project
The architecture of the project:
Now that we have our prerequisites sorted, let's create a serverless project:
Project Setup:
-
Start by creating a new serverless project using
serverless create
. Provide the project name and application name as per your preference.
-
AWS Configuration:
- Configure your AWS access and secret key when prompted.
Authentication:
- Grant access by typing "yes" when asked.
Building the Serverless Application
We've laid the foundation; now, let's build the architecture of our serverless application:
๐๏ธ Project Architecture:
Project Cloning:
- Clone the repository for your serverless project using
git clone
https://github.com/LondheShubham153/aws-node-http-api-project.git
.
- Clone the repository for your serverless project using
Change Directory:
- Navigate to the project directory using
cd aws-node-http-api-project
.
- Navigate to the project directory using
Branch Selection:
-
Switch to the 'dev' branch using
git checkout dev
.
-
Serverless Configuration:
Create a new project on the Serverless Framework website. Use
serverless --org=iamsuman007
to connect with your serverless.yaml file.-
Ensure that the application name matches the one defined in your serverless.yaml file.
Automatic Service Creation:
- The framework will automatically create all the necessary services to run your application.
Accessing the Application:
Testing and Data Validation
With your serverless application deployed, it's time to test and validate its functionality:
๐งช Testing and Validation:
Data Insertion:
Utilize the POST method to insert data into the table through your endpoint.
POST: xau655ee3l.execute-api.us-east-1.amazonaws...kaam
with Body:
{ "kaam": "making changes to the api" }
Data Validation:
- Confirm that the data is available inside the DynamoDB table.
Adding More Data:
Add more data using the POST method and validate using GET.
-
View the insertion using GET: xau655ee3l.execute-api.us-east-1.amazonaws...kaam
CI/CD Pipeline
To streamline your development process and ensure smooth deployments, set up a CI/CD pipeline:
๐ CI/CD Pipeline:
Pipeline Creation:
- Create a CI/CD pipeline for your serverless application.
Deployment:
- Ensure that your CI/CD pipeline is working seamlessly and successfully deploying changes.
Conclusion
Building a serverless Node.js application on AWS with an EC2 instance and implementing CI/CD can be a rewarding experience. With the right setup and tools, you can create, deploy, and maintain powerful serverless applications with ease. ๐
Now that you've mastered these steps, you're well-equipped to embark on your serverless journey. Happy coding and deploying! ๐ป๐๐ Checkout GitHub Repository for projects: