Skip to content

Base scaffolding project to be used as a template in other projects, stack aws lambdas with nodejs and deploy with serverless framework.

Notifications You must be signed in to change notification settings

damiancipolat/nodejs_lambda_stack

Repository files navigation

Node.js AWS - Lambda stack

This repository was created to be used as a template for future projects.

Scaffolding:

This modules are used in this project.

Environments:

The project is ready to work with 3 environments (dev / stage / production).

Configuration:

In the /config directory there are five files with a configuration schema to be used in the project: dev.json, stage.json, production.json, default.json and custom-environment-variables.json.

  • default.json: Use this file when NODE_ENV = "".
  • dev.json: Use this file when NODE_ENV = dev.
  • stage.json: Use this file when NODE_ENV = stage.
  • production.json: Use this file when NODE_ENV = production.
  • custom-environment-variables.json: this is a special file, is used to mix the configuration schema with ENVIRONMENT VARIABLES, map the variables name with environment variables with the same name, example:
{
    "system-env":{
        "loan":"LOAN_NAME",
        "table":"TABLE_NAME"
    },
    "values":{}
}

In the example "values" is empty, and the interesting structured to map is "system-env" in this object the script will map the values "LOAN_NAME" and "TABLE_NAME" with environment variables, and finally can be accesed using the config.get('system-env.loan');. Take a look later to the file serverless.yml in the "environment" section.

Install:

npm install serverless -g
npm install

Command List:

#To check es-lint rules:
npm run check

#To run unit test and coverage:
npm test

#To run deploy:
npm run deploy

Versions:

The project use SEMVER to track the changes in the package.json in the version key, there are a githook in the precommmit created using Husky that run a validation, to make sure always commit a differente package.json{version} differente. To make this is necessary to modify in the ./hooks/config.js the github api token and the development branch name.

Config.js:

module.exports = {
    token: process.env.GIT_TOKEN || 'xxxxxxxxxxxx',  <-- GITHUB API TOKEN HERE
    branch: process.env.GIT_BRANCH || 'development', <-- DEVELOPMENT BRANCH NAME HERE.
};

Make sure you have the github project url in the package.json{repository.url}, example: https://github.com/damiancipolat/nodejs_lambda_stack.

How to get the Github api token, go to this link: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token

To use this project as template:

serverless create --template-url https://github.com/damiancipolat/nodejs_lambda_stack --path [YOUR-PROJECT-PATH]

Project title:

Delete the last sections of the README.md to add in this section the new project information.

About

Base scaffolding project to be used as a template in other projects, stack aws lambdas with nodejs and deploy with serverless framework.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published