Skip to content

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

Notifications You must be signed in to change notification settings

wednesday-solutions/serverless-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

.
└── 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

Development

Local DB setup

To setup up the database locally run*:

pnpm local:db:up
  • requires docker

Run the following command to run migrations

./setup-local.sh

Creating Models

To create a new Model Test with name of type string, run:

pnpm model:generate --name Test --attributes name:string

Running migrations

To run migrations, run:

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

// 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();

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

{
	...
	statusCode: 2XX,
	body: {...}
	...
}

Error

{
	...
	statusCode: 4XX, // or 5XX
	body: {...}
}

Usage

Close the handler with statusCode and body

const baseHandler = (event, context) => {
	return new LambdaCloser(data).ok();
};

200

const response = new LambdaCloser({
	data: {...},
	message: 'response message'
}).ok();

expect(response).toEqual({
	statusCode: 200,
	body: {
		data: {...},
		message: 'response message'
	},
}); //true

201

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

// 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

Postman collection

You can find postman collection here : collection

About

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

Topics

Resources

Stars

Watchers

Forks