Skip to content

Latest commit

 

History

History

README.md

NestJS Starter-Kit - AWS Lambda Deployment

NOTE :

This project was cloned from the nestjs-starter-rest-api repository.

Please refer to the project's starter-kit's README file to understand more about the project's business logic, etc.

This README that you are viewing now talks more about how to deploy the project on AWS Lambda.

PoC Contents

Installation

# Project Dependencies:
$ npm install

# Serverless Framework:
npm install -g serverless

Running the app

We need the various required environment variables to exist in order to run the app.

Create a .env file from the template .env.template file. For more details, please refer to the starter-kit's README file.

To run the app we need this pre-requisite:

  • MySQL server running

Running the app in local

Commands:

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Running the app in serverless offline mode

$ npm run sls-offline

Deployment via serverless

We need the various required environment variables to exist in order to run the app.

We currently hard-code them in the serverless.yml file. Our recommended way is to use AWS SSM - Parameter Store and point to the SSM variable path in the serverless.yml file.

# deploy to DEV environment
npm run deploy:dev

Alternative Deployment via Lambda Container Image

Usually when we use the serverless deploy command, the framework runs serverless package in the background first, and then deploys the generated package(Lamda packages are zip files) via CloudFormation.

But as of Dec 2020, AWS Lambda allows us to package it with a Docker container image that can be up to 10 GB in size, instead of traditional zip files. That means we can have a Dockerfile with all the dependencies, push it to ECR, and just point Lambda to the AWS ECR image.

You can avail docker support with the help of serverless framework also instead of creating it manually process. Read here for more detailed steps where you start off by changing in the serverless.yml file.

External Link

Nest Logo

Nest Logo