Table of contents
- Future for Serverless
- Installation Part:
- Install Node.js 14 on Ubuntu 22.04|20.04|18.04
- Install serverless module via NPM:
- AWSCLI installation:
- My first serverless Deployment:
- Write down the serverless.yml file for this app deployment
- Deployment:
- ✔ Service deployed to stack serverless-taskmaster-app1-dev (56s)
- Architecture in AWS which we did from serverless:Cloudformation stacks
- Download Postman: to test this app and create account and login :https://www.postman.com/downloads/
- Serverless Monitoring Integration setup:
- Here is integrated monitoring..!!!
- GIT integration with AWS for CI/CD deployments:
- Serverless App deployment:
- Github project url:https://github.com/gsbarure/serverless-taskmaster-aws-app.git
- Conclusion:
- Cloudformations.
- Dynamodb.
- Cloudwatch
- AWS Lambda
- S3:
Future for Serverless
Serverless computing offers a number of advantages over traditional cloud-based or server-centric infrastructure. For many developers, serverless architectures offer greater scalability, more flexibility, and quicker time to release, all at a reduced cost. With serverless architectures, developers do not need to worry about purchasing, provisioning, and managing backend servers.
e.g.Developers are only charged for the server space they use, reducing cost
Installation Part:
Name itself says a serverless so we do not need any servers/manual intervention for the same once we install serverless.
Launch EC2 instance to install serverless.
Install Node.js 14 on Ubuntu 22.04|20.04|18.04
Update the Server:
sudo apt update
Install Node.js 14 on Ubuntu 22.04|20.04|18.04
After system update, install Node.js 14 on Ubuntu 22.04|20.04|18.04 by first installing the required repository.
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt -y install nodejs
Verify the version of Node.js installed.
Install serverless
module via NPM:
npm install -g serverless
AWSCLI installation:
sudo apt install awscli
Setup serverless aacount:https://www.serverless.com/framework/docs/getting-started
Login serverless account and navigate to existing project,copy that URL and run it in server.
Run the following command
$serverless --org=gajananbarure
Select the services depends on project requirements here e.g. AWS/HTTP API
Provide Project Name:
Login to AWS account and create IAM USER to connect serverless with AWS.
Policies for user:Administrator access.
Create access/Secret key.
My first serverless Deployment:
serverless deploy / sls deploy
Here is the Simple serverless deployement for Hello!
git clone :Project URLGithub ---https://github.com/gsbarure/serverless-taskmaster-aws-app.git
Write down the serverless.yml file for this app deployment
org: gajananbarure
app: testing-end-to-end
service: serverless-taskmaster-aws-app
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
region: us-east-1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:*
Resource:
# - arn:aws:dynamodb:us-east-1:626072240565:table/KaamKaro
- arn:aws:dynamodb:us-east-1:310133246623:table/KaamKaro
functions:
hello:
handler: src/hello.handler
events:
- httpApi:
path: /
method: get
kaamBharo:
handler: src/kaamBharo.handler
events:
- httpApi:
path: /kaam
method: post
kaamDikhao:
handler: src/kaamDikhao.handler
events:
- httpApi:
path: /kaam
method: get
kaamKhatamKaro:
handler: src/kaamKhatamKaro.handler
events:
- httpApi:
path: /kaam/{id}
method: put
resources:
Resources:
KaamKaro:
Type: AWS::DynamoDB::Table
Properties:
TableName: KaamKaro
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
Deployment:
serverless deploy / sls deploy
It may throw error as to run package.json we need npm installer.
we can see these errors through cloudwatch loggroups.
Simple solution for above error run install npm install and deploy again
Below are the endpoints created for the functions which mentioned in above serverless.yml with get/post/put methods e.g.KaamBharo/KaamDikhao/KaamKhatamkaro
use strict";
const { v4 } = require("uuid");
const AWS = require("aws-sdk");
const kaamBharo = async (event) => {
const dynamoDb = new AWS.DynamoDB.DocumentClient();
const { kaam } = JSON.parse(event.body);
const createdAt = new Date().toISOString();
const id = v4();
const newKaam = {
id,
kaam,
createdAt,
completed: false
}
await dynamoDb.put({
TableName: "KaamKaro",
Item: newKaam
}).promise();
return {
statusCode: 200,
body: JSON.stringify(newKaam),
};
};
module.exports = {
handler: kaamBharo,
};
serverless deploy / sls deploy
✔ Service deployed to stack serverless-taskmaster-app1-dev (56s)
dashboard: https://app.serverless.com/gajananbarure/apps/serverless-taskmaster-aws-app1/serverless-taskmaster-app1/dev/us-east-1 endpoint: GET - https://lq319zfrdk.execute-api.us-east-1.amazonaws.com/hello functions: hello: serverless-taskmaster-app1-dev-hello (232 kB)
Architecture in AWS which we did from serverless:Cloudformation stacks
Download Postman: to test this app and create account and login :https://www.postman.com/downloads/
Postman is a tool for API Testing.
Give App name under new collection and provide the names like below.
Create environment and put url under that so that directly we can access like
{{url name}}/pathname
To check functions/request add request
dropdown and check your functions i.e.get/post/put etc.
To write the text select below options:
Serverless Monitoring Integration setup:
Logging into the Serverless Console via the browser If your browser does not open automatically, please open this URL: https://console.serverless.com?client=cli%3Aserverless&transactionId=8fc9b3be-005b-4621-9995-344d8f586343&clientVersion=3.30.1&clientOriginCommand=onboarding
Here is integrated monitoring..!!!
go to dev mode
Testing purpose take your URL and try accessing from browser it will start reflecting like below:
GIT integration with AWS for CI/CD deployments:
Serverless App deployment:
sls remove
This command is used to remove all the Services associated with this deployment.
Github project url:https://github.com/gsbarure/serverless-taskmaster-aws-app.git
Conclusion:
Deployed serverless AWS app,tested through Postman,set up Monitoring and Integrated CI/CD through GIT.
The future holds an exciting world for serverless. Abstractions will continue to get higher and higher and make our jobs continuously easier.
Applications could become “self-aware” in the sense that they know what the best infrastructure is given the use case and amount of traffic it sees. We’re already seeing progress with infrastructure from code, and it will continue to get better with time.
We have a long way to get there and of course, this is all theoretical. But not impossible.
The tools being developed today are truly revolutionary and integrate seamlessly into your cloud vendor environments. It’s not that far of a stretch to think some of these tools can perform usage analysis and modify the infrastructure.
We have many things to look forward to with serverless in the years to come. Keep learning, keep experimenting, keep innovating.
Happy Learning..!!
Thank you Shubham Londhe..!!
AWS Services created by this serverless App:(As we did everything from serverless)
Cloudformations.
Dynamodb.
Cloudwatch
AWS Lambda
S3:
Thank you for reading!!
linkdin:linkedin.com/in/gajanan-barure-7351a4140
Happy Learning :)
Keep learning,Keep growing🎇🎇
Thank you for reading!! Hope you find this helpful.