1.0.4 • Published 1 year ago

@kunbr0/nestjs-serverless v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Introduction

Use this package to deploy your NestJS application to AWS in serverless mode.

This package will generate an CloudFormation template to create resources in AWS. Main services are:

  • AWS API Gateway
  • AWS Lambda
  • AWS Identity and Access Management (IAM)
  • AWS S3
  • ... and so on

Install package

# 1. Install package
yarn add @kunbr0/nestjs-serverless

# 2. Install other dependencies
yarn add serverless-esbuild esbuild

# 3. Check if installation ok, print package info (Optional)
npx ksls -v

Create necessary files

// ksls/lambda/RestAPIHandler/index.ts

import { deployRestAPIWithServerless } from '@kunbr0/nestjs-serverless'
import { AppModule } from 'src/app.module'

export const { handler, FunctionHandler: RestAPIHandler } = deployRestAPIWithServerless({
  appModule: AppModule,
  fileName: __filename,
})
// ksls.config.ts

import { getDeploymentConfig } from '@kunbr0/nestjs-serverless'
import { RestAPIHandler } from './ksls/lambda/RestAPIHandler'

const deploymentConfig = getDeploymentConfig({
  projectName: 'my-nestjs-app',
  stage: 'alpha',
  runTime: 'nodejs20.x',
  region: 'eu-north-1',
  services: {
    lambda: { RestAPIHandler },
  },
})

module.exports = deploymentConfig

Deploy app to AWS

# 1. Config AWS to get necessary credential / permissions
Check out this link: https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html

# 2. Run deploy command
npx ksls deploy