Table of contents
- My AWS Serverless Project Features:
- Please first refer the link given below for the prerequisites and all installation processes with simple practice serverless project.
- (part-1)
- Now its time to clone the code from github
- Write down the serverless.yml file for this deployment
- Let's break down the important sections and their functionalities:
- Now open the Postmen app for api testing
- AWS lambda monitoring
- Now creating a CI/CD (Continuous Integration/Continuous Deployment)
- Conclusion
My AWS Serverless Project Features:
Serverless Architecture: No need to manage infrastructure, enabling scalability.
API Gateway Integration: Easy creation and management of secure RESTful APIs.
DynamoDB for Data Storage: Efficient and scalable NoSQL database.
Event-Driven Processes: Triggered by events like file uploads or database changes.
Infrastructure as Code (IaC): Consistent provisioning and deployment using AWS CloudFormation.
CI/CD and Automation: Automated build, test, and deployment with AWS CodePipeline.
Monitoring and Logging: Capturing logs, setting alarms, and analyzing performance using AWS CloudWatch.
Security and Access Control: IAM for secure access and permissions management.
Cost Optimization: Pay only for actual execution time and resources used.
These features highlight the benefits and effectiveness of AWS serverless architecture in my project.
Please first refer the link given below for the prerequisites and all installation processes with simple practice serverless project.
(part-1)
" https://lnkd.in/dS-MAJaS"
Now its time to clone the code from github
Write down the serverless.yml file for this deployment
org: mehboob1129
app: serverless-taskmaster-aws-app
service: serverless-taskmaster-aws-app
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
region: ap-south-1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:*
Resource:
- arn:aws:dynamodb:ap-south-1:272112857859: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
The provided code is a configuration file written in YAML format for an AWS Serverless Application using the Serverless Framework.
Let's break down the important sections and their functionalities:
org: mehboob1129
This metadata field represents the Organisation.app: serverless-taskmaster-aws-app
: This is name of the application.service: serverless-taskmaster-aws-app
: Specifies the name of the service being defined.frameworkVersion: '3'
: Indicates the version of the Serverless Framework being used.provider
: Describes the AWS provider settings.name: aws
: Specifies the provider as AWS.runtime: nodejs14.x
: Specifies the runtime environment for the functions as Node.js 14.x.region: us-east-1
: Specifies the AWS region where the resources will be deployed.iamRoleStatements
: Defines IAM role statements, allowing DynamoDB-related actions on the specified resource.
functions
: Defines individual functions in the service along with their event triggers.Each function has a unique identifier (
hello
,kaamBharo
,kaamDikhao
,kaamKhatamKaro
) and specifies the handler file and function within it.Event triggers are defined with the
events
keyword and can be HTTP-based triggers (httpApi
).
resources
: Defines AWS resources that will be provisioned as part of the service.- Here, a DynamoDB table (
KaamKaro
) is defined with its properties, including the table name, billing mode, attribute definitions, and key schema.
- Here, a DynamoDB table (
This configuration sets up a serverless application with four functions that handle HTTP requests and interact with a DynamoDB table named KaamKaro
.
Now Deploy the application:
serverless login
Login to serverless CLI
- Use this command to deploy application on serverless CLI.
serverless deploy / sls deploy
-
CloudFormation/Stacks/serverless-taskmaster-aws-app-devUpdate stack
Go to "View in Designer"
Cloudformation Stack Diagram is Readyππ
We have successfully deployed our serverless application
Now open the Postmen app for api testing
"https://hpmw2rora7.execute-api.ap-south-1.amazonaws.com"
This is the URL of our application that we can use to create a new request in Postman.
- Set the request method to the appropriate method for the API endpoint you want to test. For example, if the endpoint is a GET request, then the request method should be set to "GET".
"GET"=Get the data from your server
- Click on the "Send" button to send the request to the API endpoint.
"Environment variables" feature in Postman to store frequently used values, such as the URL of the API endpoint and the authorization credentials. This will make it easier to create and run requests.
kaambharo
"Post" = Update your data
Set the request method to "POST".
In Body select 'raw' and for code select 'JSON'
write the message that you want to show in curly brackets .
{ "kaam":"Add new projects " }
In url select the variable /kaam
Click on the "Send" button to send the request to the API endpoint.
KaamKhatamKaro
"Put" = insert your data
Set the request method to "PUT".
In Body select 'raw' and for code select 'JSON'
write the message that you want to show in curly brackets .
{ "completed":true }
In url select the variable/kaam/ID (you will get this id from the result of post API request)
Click on the "Send" button to send the request to the API endpoint.
AWS lambda monitoring
AWS Lambda monitoring is a set of features that allow you to track the performance and health of your Lambda functions. These features include metrics, logs, traces, and insights. You can use Lambda monitoring to identify performance bottlenecks and errors, troubleshoot problems, and ensure that your functions are performing as expected.
Run command
serverless dev
in the terminal to initialise dev mode in serverless.Once initialising is done intigrate aws lambda with serverless and aws account.
- "Monitoring integrated"
- By clicking on play button we can create automation in monitoring β¨
Now creating a CI/CD (Continuous Integration/Continuous Deployment)
Steps to create ci/cd pipeline
Open your serverless account
Click on your project
Go to settings
Click on CI/CD
Search your project Repository - Select your region (ap-south-1) - Select branch (Master) and stage (Dev)
- Login to Github and confirm integration
Once you have created your CI/CD pipeline, you can commit your code to your GitHub repository and push it to the master branch. GitHub Actions will then automatically build, test, and deploy your project to AWS.
Now EC2 instance is not required we have integrated github with serverless we can STOP EC2 instance .
Make some changes in github code and commit to master branch
It will deploy our project automatically β¨β¨β¨
β¨**"Successfully completed our serverless project"**β¨
Conclusion
The AWS Serverless project features serverless architecture, API Gateway integration, DynamoDB for data storage, event-driven processes, Infrastructure as Code (IaC) with AWS CloudFormation, CI/CD and automation using AWS CodePipeline, monitoring and logging with AWS CloudWatch, security and access control with IAM, and cost optimization by paying only for actual resource usage.
The serverless.yml file provides configuration for the deployment. The application has four functions handling HTTP requests and interacting with a DynamoDB table named KaamKaro.
Postman is used to test the API endpoints, including GET, POST, and PUT requests. Monitoring is integrated with AWS Lambda, and a CI/CD pipeline is set up using GitHub Actions for continuous integration and deployment.
In conclusion, the AWS Serverless project showcases the advantages of serverless architecture, such as scalability, easy deployment, cost optimization, and efficient event handling.