Skip to content

Basic Node.js Serverless (framework) boilerplate which includes individual lambda functions, local S3, GitLab CI/CD with different environments, and a basic API Gateway.

Notifications You must be signed in to change notification settings

dhavall08/serverless-nodejs

Repository files navigation

Serverless

I've created a basic structure using serverless framework which includes individual lambda functions, GitLab CI/CD with different environments, and a basic API Gateway. I've also added some of the reference links for more information.

Setup

  1. Create a .env.dev file by taking reference of env.dev.example.
  2. Install packages using npm i.

Start local server

  • Run locally using npm start or you can also debug using VSCode (F5).
  • Test and upload files to local S3 for testing (find a sample function inside).

Deployment

First time deployment

  • AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables must be set in GitLab CI/CD variables.
  • Add other environments to GitLab CI/CD variables separately for staging and production.

Update deployment

There are following GitLab pipelines that deploy to AWS whenever we push any changes.

  • The staging branch is deployed to the staging url.
  • The master branch is deployed to the production url.

Notes:

  • It compares hash while deploying. So, it skips deploying of a particular lambda function if it hasn't been changed.
  • Any change in env needs to re-deploy all the functions using it.

Create packages in local

If you want to create packages, use npm run package. This will create a .serverless folder with all the individual zip files.

Some Reference Links

About

Basic Node.js Serverless (framework) boilerplate which includes individual lambda functions, local S3, GitLab CI/CD with different environments, and a basic API Gateway.

Topics

Resources

Stars

Watchers

Forks