Skip to content

Template to build customizable, flexible and well documented APIs with Node and AWS Lambda.

License

Notifications You must be signed in to change notification settings

andersoncontreira/serverless-lambda-api-node-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serverless-node-template (Work in progress...)

Template to build customizable, flexible and well documented APIs with Node.js and Express.

Service Architecture

Diagrams of the project architecture and others.

More details here.

Cloud Architecture

Example of the architecture that runs on AWS Cloud.

Docker Architecture

Example of the architecture that runs with docker.

Routes of the service

Lista od routes:

GET / - Root
GET /docs - Swagger docs
GET /alive - Health Check
GET /v1/product - Product List
POST /v1/product - Product Create
DELETE /v1/product/<uuid> - Soft Product Delete
GET /v1/product/<uuid> - Product Get
PATCH /v1/product/<uuid> - Soft Product Update
PUT /v1/product/<uuid> - Complete Product Update

Prerequisites

  • docker
  • docker-compose
  • node
  • express
  • typescript
  • jest
  • mocks
  • yarn

Features

  • Projects Guidelines (Best practices)
  • Docker Management (Docker-Compose)
  • Localstack
  • MySQL
  • Redis
  • OpenApi (Swagger)
  • GitHub Actions
  • Tests (Unit, Component, and Integration)
  • Coverage Reports
  • Code formatter (Prettier)
  • Lint (ESlint)
  • Standard commits (Commitizen)
  • Standard files setup (Editorconfig)
  • REST (RESTful & HATEOS)
  • CodeQuality (Sonar)
  • Database Migrations (Sequelize)

Kong configuration

Configure Kong API Gateway to work with API Gateway compatibility.

Installation

Installing AWS CLI

Docs: https://docs.aws.amazon.com/en/cli/latest/userguide/install-cliv2.html

Execute the follow command:

apt install awscli

Execute the follow command:

aws configure

Creating the Docker network

Execute the follow command:

./scripts/docker/create-network.sh

Running locally

To nd install the modules, execute the follow command:

yarn install

Executing only the HTTP framework

Execute the follow command:

yarn run start:dev

Executing by Docker

To build execute the follow command:

./scripts/runenv.sh --build

Execute the follow command:

./scripts/runenv.sh

Recovering the environment in error cases

Execute the follow command:

./scripts/fixenv.sh

Information about automation scripts

The following describes the use of automation scripts. These kebab case scripts help the developer in general tasks.

General scripts

Kebab case scripts to help the developer with general tasks.

General scripts

Kebab case scripts to help the developer with general tasks.

Script Description Context
boot.sh Starts the application while the container is running Local boot
boot-db.sh Starts data to database Local boot
boot-queues.sh Start application queues in localstack Local boot
boot-validate-connection.sh Check if localstack is ready to connect Local boot
commit.sh Run the communitarization tool to commit the message Local development
fixenv.sh In some cases where the network is deleted, you can correct the container references Local install
pre-commit-config.sh Script to prepare the local environment to run pre-commit tools Local development
preenv.sh Script to run pre-build commands Local boot
runenv.sh Script to start the project locally Local development
testenv.sh Script to run the environment focusing on component tests Local development

Docker scripts

Scripts that facilitate tasks for docker context;

Localstack scripts

Scripts that help execute commands on Localstack resources such as S3, SQS, Lambda, etc.

Samples

See the project samples in this folder here.

Running tests

To run the unit tests for the project, you can run the following command:

Unitary tests:

Running the tests:

yarn run test

Component tests:

Start the docker containers:

./scripts/testenv.sh

Running the tests:

yarn run test:component

Integration tests:

Copy the env/integration.env.example file to env/integration.env and edit with the staging parameters.

Running the tests:

yarn run test:integration

End-2-End tests:

Running the tests:

yarn run test:e2e

All tests:

Running the tests:

yarn run test:all

Generating coverage reports

To run the coverage tests, you can run the following commands:

Unit Test Coverage:

Run the follow command:

yarn run test:cov

Component Test Coverage:

Start the docker containers:

./scripts/testenv.sh

Run the follow command:

yarn run test:component-cov

Integration test coverage:

Copy the env/integration.env.example file to env/integration.env and edit with the staging parameters.

Run the follow command:

yarn run test:integration-cov

Note: The result can be found in the target/* folder.

License

See the license: LICENSE.md.

Contribution

Lint

To run the lint in the project's source code, run the following command:

yarn run lint

Code Format

To run the code formation on the project's source code, run the following command:

yarn run format

Pre-commit

To install pre-commit execute the follow command:

./scripts/pre-commit-config.sh

Build

To execute the build of the project execute the follow command:

yarn run build

Guidelines

To execute the guidelines validation of the project execute the follow command:

./scripts/guidelines-checker.py

About

Template to build customizable, flexible and well documented APIs with Node and AWS Lambda.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published