A repository of Serverless applications showcasing how to orchestrate cloud infrastructure for varied use cases with multiple cloud infrastructure providers.
We’re always looking for people who value their work, so come and join us.
We are hiring!
This is serverless template. This will help you get started with serverless architecture.
We follow clean code.
.
└── src/
├── drivers
│ └── models
├── interface-adaptors
└── use-cases
- Layer #1 for frameworks and drivers.
- This example uses Sequelize, Model definitions are written in this folder
- AWS SDK client creation should be done in this folder
- Layer #2 for adaptors that sit in between your drivers and the business logic.
- Write your DAOs here
- do not use Models or SDK directly
The software in this layer is a set of adapters that convert data from the format most convenient for the use cases and entities, to the format most convenient for some external agency such as the Database or the Web.
- Layer #3, for your business logic.
- Serverless Aurora cluster
- Subnets
- Public Route Table
- Private Route Table
- Security Groups
- VPC
- Elastic IP
- NAT Gateway
- Internet Gateway
- IAM Roles
- Lambdas
To setup up the database locally run*:
pnpm local:db:up
- requires docker
Run the following command to run migrations
./setup-local.sh
To create a new Model Test with name of type string, run:
pnpm model:generate --name Test --attributes name:string
To run migrations, run:
pnpm db:migrate
Build a handler for your lambda with a set of basic middy middlewares.
Create a new handler with the basic middlewares
// index.js
const baseHandler = (event, context) => {
// write logic here
};
export const handler = new LambdaBuilder(baseHandler)
.buildBasicMiddlewares()
.getLambdaHandler();
Also supports Schema Validation , just pass schema in basicMiddleware
export const handler = new LambdaBuilder(baseHandler)
.buildBasicMiddlewares(schema)
.getLambdaHandler();
If you are using the APIGateway, this Class will help you construct success and error responses.
APIGateway expectes the following response signatures.
{
...
statusCode: 2XX,
body: {...}
...
}
{
...
statusCode: 4XX, // or 5XX
body: {...}
}
const baseHandler = (event, context) => {
return new LambdaCloser(data).ok();
};
const response = new LambdaCloser({
data: {...},
message: 'response message'
}).ok();
expect(response).toEqual({
statusCode: 200,
body: {
data: {...},
message: 'response message'
},
}); //true
const response = new LambdaCloser({
data: {...},
message: 'response message'
}).created();
expect(response).toEqual({
statusCode: 201,
body: {
data: {...},
message: 'response message'
},
}); // true
The LambdaCloser promotes usage of predefined error codes and error code messages.
Define your error code in utils/error-code.js and add a message for the code in utils/error-code-messages.js
// create an error code in error-codes.js
const ERROR_CODES = {
E1: 'E1',
};
// create an error code message for the code in error-code-messages.js
const ERROR_CODE_MESSAGES = {
E1: 'Custom error message',
};
const response = new LambdaCloser({
code: 'E1',
}).badRequest();
expect(response).toEqual({
statusCode: 400,
body: {
message: 'Custom error message',
code: 'E1',
},
}); // true
We have different lambda functions for showcasing :
- CRUD options for Todo
- Cron jobs
- Cognito triggers
You can find postman collection here : collection