Description
It is a serverless application that uses AWS lambda, dynamodb, and api gateway. It is written in typescript and uses the serverless framework.
Setup
Prerequisites
- nodejs
- npm
- serverless framework
- aws cli
- aws credentials
- dynamodb local
- dynamodb admin
- dynamodb migrate
- Java Runtime Engine (JRE) version 6.x or newer
Features
- User
- Create a user
- Get a user
- Update a user
- Delete a user
- Shop
- Create a shop
- Get a shop
- Mail - send an email via AWS SES
Installation
Setup npm dependencies
Setup serverless framework
Install dynamodb local
DynamoDb Oflline Plugin Requires:
- serverless@^1
- Java Runtime Engine (JRE) version 6.x or newer
Install dynamodb admin
after installation, run the following command to start dynamodb admin
_note: admin will be available at http://localhost:8001
Install dynamodb migrate
Run
Deploy
Remove
API Documentation
Will be available at http://localhost:3000/swagger
Project Structure
+-- functions
| | +-- handler.ts
| | +-- routes.ts
| +-- shop
| | +-- handler.ts
| | +-- routes.ts
| +-- user
| +-- handler.ts
| +-- routes.ts
+-- libs
| +-- api-gateway.ts
| +-- handler-resolver.ts
| +-- lambda.ts
+-- model
| +-- Shop.ts
| +-- User.ts
| +-- index.ts
+-- services
+-- index.ts
+-- shop-service.ts
+-- user-service.ts
Each function has its own folder with a handler and routes file. The handler file contains the lambda function and the routes file contains the api gateway routes. Example of the handler file:
{
type: 'object',
required: ['body'],
properties: {
body: {
type: 'object',
required: ['email'],
properties: {
email: { type: 'string', format: 'email' },
},
},
},
},
async (event: APIGatewayProxyEventWithBody<any>): Promise<APIGatewayProxyResult> => {
const user = await userService.create({
email: event.body.email,
userId: uuidv4(),
isVerified: false,
});
return formatJSONResponse({
user,
});
},
);
middify - is a helper function that wraps the lambda function with params validation and error handling.
Contributing Guide
Branching
master- production branchdev- development branchfeature/- feature branchbugfix/- bugfix branchhotfix/- hotfix branchrelease/- release branchdocs/- documentation branchtest/- test branchchore/- chore branchrefactor/- refactor branchstyle/- style branchci/- ci branch
Commit Message
Example:
Commit message should be with the next format - conventionalcommits We are use commitizen for commit message formatting.