Mega project on AWS serverless ...

Mega project on AWS serverless ...

(Part-2)

Β·

6 min read


My AWS Serverless Project Features:

  1. Serverless Architecture: No need to manage infrastructure, enabling scalability.

  2. API Gateway Integration: Easy creation and management of secure RESTful APIs.

  3. DynamoDB for Data Storage: Efficient and scalable NoSQL database.

  4. Event-Driven Processes: Triggered by events like file uploads or database changes.

  5. Infrastructure as Code (IaC): Consistent provisioning and deployment using AWS CloudFormation.

  6. CI/CD and Automation: Automated build, test, and deployment with AWS CodePipeline.

  7. Monitoring and Logging: Capturing logs, setting alarms, and analyzing performance using AWS CloudWatch.

  8. Security and Access Control: IAM for secure access and permissions management.

  9. 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.


(part-1)


" https://lnkd.in/dS-MAJaS"


Now its time to clone the code from github

"My Github Repository URL"

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.

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
  1. 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.

  1. 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

  1. 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

  1. Set the request method to "POST".

  2. In Body select 'raw' and for code select 'JSON'

  3. write the message that you want to show in curly brackets .

     {
         "kaam":"Add new projects "
     }
    
  4. In url select the variable /kaam

  5. Click on the "Send" button to send the request to the API endpoint.

KaamKhatamKaro

"Put" = insert your data

  1. Set the request method to "PUT".

  2. In Body select 'raw' and for code select 'JSON'

  3. write the message that you want to show in curly brackets .

     {
         "completed":true
     }
    
  4. In url select the variable/kaam/ID (you will get this id from the result of post API request)

  5. 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.

  1. Run command serverless dev in the terminal to initialise dev mode in serverless.

  2. Once initialising is done intigrate aws lambda with serverless and aws account.

  1. "Monitoring integrated"

  1. 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

  1. Open your serverless account

  2. Click on your project

  3. Go to settings

  1. Click on CI/CD

  2. Search your project Repository - Select your region (ap-south-1) - Select branch (Master) and stage (Dev)

  1. 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.

Β