Serverless on AWS
Aashish R.
????System Engineer at Tata Consultancy Services | DevOps | Terraform | Kubernetes | Ansible | Jenkins | CI/CD | ??AWS | Docker | Grafana | GitHub | Linux |
Are you excited to know about serverless architecture!! You can build and run applications without thinking about servers.
What is serverless?
Serverless is a cloud-native development model that allows you running code, managing data, and integrating applications, all without managing servers.
Serverless technologies feature automatic scaling, built-in high availability, and a pay-for-use billing model to increase agility and optimize costs. These technologies also eliminate infrastructure management tasks like capacity provisioning and patching, so you can focus on writing code that serves your customers. Serverless applications start with AWS Lambda, an event-driven compute service natively integrated with over 200 AWS services and software as a service (SaaS) applications.
You no longer have to provision, scale, and maintain servers to run your applications, databases, and storage systems.
Why use serverless architectures?
By using a serverless architecture, your developers can focus on their core product instead of worrying about managing and operating servers or runtimes, either in the cloud or on-premises. This reduced overhead lets developers reclaim time and energy that can be spent on developing great products which scale and that are reliable.
Here are ?benefits to using a serverless architecture?for your project.
The leading advantage is that your developers can focus their attention on product development. They no longer have to account for managing and operating servers. Components like network configuration or the physical security of your servers are handled by the vendor rather than your team.
Serverless is more efficient
A serverless architecture means that you pay per request. If you had a traditional server, you’d keep it running at all times. With a serverless architecture, you’re only charged when the server’s used. That means there is less waste generated as well.
Serverless is easy to deploy
If you need to spin up an app fast, serverless might be your solution. Instead of weeks and months to deploy an app, you can do it within hours and days. The reason behind this is that you don’t have to concern yourself with infrastructure. You can focus on the code and release it immediately. Scalability is automatic and you don’t have to worry about any provisioning needs.
Low cost
Going serverless is a great way of?cutting cost. That’s because you’re outsourcing the responsibilities of managing servers, databases, and some logic. Besides the actual cost, serverless takes less computing power and human resources.you can focus on the server-side code that matters. There are situations where the cost isn’t that much cheaper, but it’ll depend on your use case.
Better scalability
Going with a serverless architecture allows you to roll with the punches. If your app succeeds and grows, it’ll be easy to stage changes that accommodate the growth.
Quick deployments and updates are possible
Developers can very quickly upload bits of code and release a new product. They can upload code all at once or one function at a time, since the application is not a single monolithic stack but rather a collection of functions provisioned by the vendor. This also makes it possible to quickly update, patch, fix, or add new features to an application. It is not necessary to make changes to the whole application; instead, developers can update the application one function at a time.
Now we are going deploy Serverless Architecture
Lambda function: AWS Lambda is a compute service that lets you run code without provisioning or managing servers.
Dynamo DB: Is aligned with the values of Serverless applications: automatic scaling according to your application load, pay-per-what-you-use pricing, easy to get started with, and no servers to manage.
API Gateway: Is the piece that ties together Serverless functions and API definitions.
S3: To store application data that doesn’t fit into a database.
IAM: Interact with other AWS services and resources in your account.
CloudWatch: Application Insights helps you monitor the AWS resources in your applications to help identify potential issues.
Required pre-requisite to deploy Serverless Architecture
Update instance/System
sudo apt update
Install NodeJS
sudo apt install nodejs
Check versions
Install Node version through nvm
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
nvm install 16.0.0
Install Serverless
npm install -g serverless
run the serverless command:
serverless
As per requirement of project you can choose any serverless project as shown below:
In this project we will clone the GitHub repo
https://github.com/LondheShubham153/aws-node-http-api-project.git
use git checkout for dev branch
领英推荐
Now we have create an account on serverless:
Click on create app to select option as per your project requirement
Click on Existing Project
Run the following command
Run this command and select create a new app
Then you can select yes option
Now your app can deploy successfully and you will get the output like this
In above images after deployment you will see GET,POST and PUT requests.
Now we have to copy these URL's and run into the Postman tool:
What is Postman?
Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
You have to create an account on https://www.postman.com/
After creating an account we have run the URL's in postman tool:
GET request- This operation reads information from a record in the database. PUT request- This operation changes a record's information in the database. POST request- This operation creates a new record in the database.
GET request Output:
Put request OUTPUT
Before sending the POST request we have to go to Body section and select raw to write JSON query as you see below ss.
Before sending the PUT request we have to go to Body section and select raw to write JSON query as you see below ss.
for JSON query you have to go to AWS DynamoDB
Click on Tables -> Name -> Explore items -> Items returned -> id (string)
click on id you will get the JSON view and paste it into Body and raw section and put that id at the end of the PUT url:
Now your application will be accessible from serverless dashboard
Now you can view your application stack on CloudFormation
CloudFormation -> Stacks -> Stack info -> Stack ID -> Template -> View in Designer
You will get flow chart of your entire project
For more DevOps related project you can reach out to me https://www.dhirubhai.net/in/aashish-r-59397bb8/
Happy Learning!!