https://github.com/wednesday-solutions/serverless-template
Cloud management demands efficiency, and the Serverless Template is your key to streamline and simplify. Your ready to use batteries included serverless-framework boilerplate. Comes with lambdas, rds, and a bunch of things pre-configured
https://github.com/wednesday-solutions/serverless-template
aurora aws aws-lambdas lambdas rds serverless-boilerplate serverless-framework serverless-starter serverless-starter-kit serverless-template step-functions
Last synced: about 1 month ago
JSON representation
Cloud management demands efficiency, and the Serverless Template is your key to streamline and simplify. Your ready to use batteries included serverless-framework boilerplate. Comes with lambdas, rds, and a bunch of things pre-configured
- Host: GitHub
- URL: https://github.com/wednesday-solutions/serverless-template
- Owner: wednesday-solutions
- Created: 2022-08-08T13:52:31.000Z (almost 3 years ago)
- Default Branch: dev
- Last Pushed: 2024-07-10T07:10:15.000Z (11 months ago)
- Last Synced: 2025-04-13T21:13:08.701Z (about 1 month ago)
- Topics: aurora, aws, aws-lambdas, lambdas, rds, serverless-boilerplate, serverless-framework, serverless-starter, serverless-starter-kit, serverless-template, step-functions
- Language: JavaScript
- Homepage: https://wednesday.is/?utm_source=github&utm_medium=serverless-template
- Size: 2.03 MB
- Stars: 9
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![]()
Serverless Template
A repository of Serverless applications showcasing how to orchestrate cloud infrastructure for varied use cases with multiple cloud infrastructure providers.
---
Expert teams of digital product strategists, developers, and designers.
---
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.
# Architecture
We follow [clean code](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html).
```
.
└── src/
├── drivers
│ └── models
├── interface-adaptors
└── use-cases
```## drivers
- 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## interface-adaptors
- 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.## use-cases
- Layer #3, for your business logic.
# Creation of the following resources is automated
- [Serverless Aurora cluster](resources/config/rds.yml)
- [Subnets](resources/config/subnet.yml)
- [Public Route Table](resources/config/route-public.yml)
- [Private Route Table](resources/config/route-private.yml)
- [Security Groups](resources/config/security-groups.yml)
- [VPC](resources/config/vpc.yml)
- [Elastic IP](resources/config/elastic-ip.yml)
- [NAT Gateway](resources/config/nat-gateway.yml)
- [Internet Gateway](resources/config/internet-gateway.yml)
- [IAM Roles](resources/config/roles.yml)
- [Lambdas](resources/lambda/functions.yml)# Development
## Local DB setup
To setup up the database locally run\*:
```sh
pnpm local:db:up
```- requires docker
Run the following command to run migrations
```sh
./setup-local.sh
```## Creating Models
To create a new Model Test with name of type string, run:
```sh
pnpm model:generate --name Test --attributes name:string
```## Running migrations
To run migrations, run:
```sh
pnpm db:migrate
```## Lambda Builder
Build a handler for your lambda with a set of basic middy middlewares.
### Usage
Create a new handler with the basic middlewares
```javascript
// index.jsconst 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();```
## Lambda Closer
If you are using the APIGateway, this Class will help you construct success and error responses.
APIGateway expectes the following response signatures.
### Success
```javascript
{
...
statusCode: 2XX,
body: {...}
...
}
```### Error
```javascript
{
...
statusCode: 4XX, // or 5XX
body: {...}
}
```### Usage
### Close the handler with statusCode and body
```javascript
const baseHandler = (event, context) => {
return new LambdaCloser(data).ok();
};
```#### 200
```javascript
const response = new LambdaCloser({
data: {...},
message: 'response message'
}).ok();expect(response).toEqual({
statusCode: 200,
body: {
data: {...},
message: 'response message'
},
}); //true
```#### 201
```javascript
const response = new LambdaCloser({
data: {...},
message: 'response message'
}).created();expect(response).toEqual({
statusCode: 201,
body: {
data: {...},
message: 'response message'
},
}); // true
```### Predefined Error codes and messages
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
#### 400
```javascript
// 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
```# Lambda Functions
We have different lambda functions for showcasing :
- CRUD options for Todo
- Cron jobs
- Cognito triggers[functions](https://github.com/wednesday-solutions/serverless-template-todo/tree/dev/functions)
# Postman collection
You can find postman collection here : [collection](https://github.com/wednesday-solutions/serverless-template-todo/tree/dev/postman)