Git Product home page Git Product logo

wednesday-solutions / serverless-template Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 0.0 2.08 MB

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

Home Page: https://wednesday.is

JavaScript 99.67% Shell 0.33%
aurora aws aws-lambdas lambdas rds serverless-framework step-functions serverless-boilerplate serverless-starter serverless-template

serverless-template's Introduction

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

serverless-template's People

Contributors

abhishek-ws avatar adidoshiws avatar christin-wednesday avatar deepak-buildd avatar deepak-wednesday avatar rohanjoby-ws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.