This repository holds the backend resources for coupon code validator
- AWS Lambda
- Amazon DynamoDB
- Amazon API Gateway
- Serverless Framework for IaC.
- GitHub actions for CI/CD.
- Webpack for bundling code.
- ESLint for code linting.
- Clone this repository
- This will install all the required dependencies.
- format all the files using ESLint
- Packages the code using WebPack
- This command will deploy the resources to AWS using dev credentials
.
├── .gitHub # CI/CD workflow for GitHub actions
├── CreateCouponCode # Lambda code to create a new coupon code
├── ListCouponCodes # Lambda code to list all the coupon codes
├── ValidateCouponCodes # Lambda code to validate the coupon code and return discount amount
├── helpers # Folder holding constants and helper functions for other lambdas
├── serverless.yml # Serverless framework resource configuration file
├── TestFiles # Testing files helpful to test APIs using postman or lambda console
├── LICENSE
└── README.md
The following is the list of steps that is executed as a part of the CI/CD setup:
- Store all account credentials in GitHub secrets to access them in environment without exposing. The AWS credentials will be used for deploying the application into your AWS account.
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
DEV_REGION: ${{secrets.DEV_REGION}}
PROD_REGION: ${{secrets.PROD_REGION}}
- Install serverless
- Install npm
- Bundle project using webpack
- Deploy to dev environment: Singapore (ap-southeast-1)
- Deploy to prod environment: Mumbai (ap-south-1)
- Fetch the deployed API endpoint for create coupon code POST API from API Gateway console or from GitHub actions dev-deploy/prod-deploy job
- Open Postman
- Paste the API endpoint in Postman with Method as POST
- From
TestFiles
folder copy the contents from thecreateCouponCodes.json
file, change values accordingly and paste in the body of POST API - Click "Send"
- You should get 201 status code with created item as response.
- Alternatively, If you want to test from Lambda console, Go to deployed lambda in test event paste contents of
createCouponCode-apigw.json
and hit "Test"
- Fetch the deployed API endpoint for List coupon codes GET API from API Gateway console or from GitHub actions dev-deploy/prod-deploy job
- Open Postman
- Paste the API endpoint in Postman with Method as GET
- Click "Send"
- You should get 200 status code with array of all the items as response
- Alternatively, If you want to test from Lambda console, Go to deployed lambda and hit "Test"
- Fetch the deployed API endpoint for Validate coupon code GET API from API Gateway console or from GitHub actions dev-deploy/prod-deploy job
- Open Postman
- Paste the API endpoint in Postman with Method as GET
- Go to
Params
tab in Postman and add two keys "couponCode" & "totalCartAmount" with the appropriate values - Click "Send"
- You should get 200 status code with the object consisting two parameters "isValid" & "discountAmount" as response body
- Alternatively, If you want to test from Lambda console, Go to deployed lambda in test event paste contents of
validateCouponCode-apigw.json
and hit "Test"