Git Product home page Git Product logo

n4u77i / orders-warranty-renewal-serverless-app Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 415 KB

This is a practice project for learning Serverless framework. The project will utilize AWS resources for serverless infrastructure. Following resources will be used: S3, IAM, API Gateway, Lambda, DynamoDB, SNS, SES, CloudFormation

TypeScript 100.00%
api-gateway cloudformation dynamodb lambda-functions s3-buckets serverless-framework ses sns-notifications

orders-warranty-renewal-serverless-app's Introduction

Serverless - AWS Node.js Typescript

This project has been generated using the aws-nodejs-typescript template from the Serverless framework.

For detailed instructions, please refer to the documentation.

About the project

This project is about creating orders and renewing them when expired. When the order is created by user, the warranty is added which will get expire after two years when order is created.

When the order is expired (TTL expires), it gets deleted (from dynamodb) and a notification is sent to the user to their email or phone numebr via SES or SNS respectively (lambda is triggered on REMOVE stream event).

At the same time, new record is added in dynamodb with same data except for a TTL of 30-days. Users will get a link in the notification to renew their order which will be valid for 30-days.

If order is renewed, it will then expire after next two years otherwise it will be deleted automatically from dynamodb permanently.

Note: The services SNS and SES used in this project are configured to run in sandboxed environment to avoid charges.

Installation/deployment instructions

Depending on your preferred package manager, follow the instructions below to deploy your project.

Requirements: NodeJS lts/fermium (v.14.15.0). If you're using nvm, run nvm use to ensure you're using the same Node version in local and in your lambda's runtime.

Using NPM

  • Run npm i to install the project dependencies
  • Run npx sls deploy to deploy this stack to AWS

Using Yarn

  • Run yarn to install the project dependencies
  • Run yarn sls deploy to deploy this stack to AWS

Using Serverless

  • Run sls deploy to deploy this stack to AWS

Testing the service

This template contain five lambda functions, four of them are triggered by an HTTP request made on the provisioned API Gateway REST API:

  • / route with POST method which takes body input in JSON format.
  • /user/{userId} and /order/{orderId} routes with GET methods.
  • /renew route with PUT method to update specific order.
  • And the last lambda function is triggered by the dynamodb stream on the REMOVE event when TTL of a record is expired.

The body structure is tested by API Gateway against the following:

  1. src/functions/createOrder/index.ts
  2. src/functions/getOrder/index.ts
  3. src/functions/getOrders/index.ts
  4. src/functions/sendOrder/index.ts
  5. src/functions/updateOrder/index.ts

Testing the endpoints

  • The / route with POST method requires data in the body in a JSON format.
    • The required params are companyName and carName of type string and number respectively.
    • Third param can either be phoneNumber or email of string. Country code is required before number.
    {
        "phoneNumber": "+920000000000",
        "companyName": "Dodge",
        "carName": "Challenger SRT Hellcat"
    }
    
    OR
    {
        "email": "[email protected]",
        "companyName": "Dodge",
        "carName": "Challenger SRT Hellcat"
    }
    
  • The /user/{userId} route with a GET method requires the userId which can be a phoneNumber or email entered when creating order. This route will be used to query all order of a user.
  • The /order/{orderId} route with a GET method requires the orderId to get specific order.
  • The /renew route with a PUT method requires orderId in query param of URL to update order. The exact route will be /renew?orderId={orderId}

All endpoints are tested on Postman

⚠️ As is, this template, once deployed, open public endpoints within your AWS account resources. Anybody with the URLs can actively execute the API Gateway endpoint and the corresponding lambda. You should protect these endpoints with the authentication method of your choice.

Project structure

The project code base is mainly located within the src folder. This folder is divided in:

  • functions - containing code base and configuration for your lambda functions
  • libs - containing shared code base between your lambdas
.
├── src
│   ├── functions               # Lambda configuration and source code folder
│   │   ├── createOrder
│   │   │   └── index.ts        # Export of handler for createOrder lambda function
│   │   ├── getOrder
│   │   │   └── index.ts        # Export of handler for getOrder lambda function
│   │   ├── getOrders
│   │   │   └── index.ts        # Export of handler for getOrders lambda function
│   │   ├── sendOrder
│   │   │   └── index.ts        # Export of handler for sendOrder lambda function
│   │   └── updateOrder
│   │       └── index.ts        # Export of handler for updateOrder lambda function
│   └── libs                    
│       ├── apiGateway.ts       # API Gateway specific helper functions
|       └── dynamo.ts           # Methods for interacting with dynaomo db 
├── serverless
│   ├── functions.ts            # Handlers path for lambda functions
|   └── dynamoResources.ts      # To add aws dynamo db resource
├── package.json
├── serverless.ts               # Serverless service file
├── tsconfig.json               # Typescript compiler configuration
├── tsconfig.paths.json         # Typescript paths
└── webpack.config.js           # Webpack configuration

orders-warranty-renewal-serverless-app's People

Contributors

n4u77i avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ramishtrail5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.