AWS - Deploy Nest.js Server to Elastic Beanstalk

Update package.json

  1. Update build, prestart, start

  2. Move @nestjs/cli and @types/node from devDependencies to dependencies

{
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "prestart": "npm run build",
    "start": "node dist/main",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
  },
  "dependencies": {
    "@nestjs/cli": "^7.0.0",
    "@types/node": "^13.9.1",
  }
}

Dockerfile

# Build
FROM node:12

WORKDIR /usr/src/app

COPY package.json .
COPY yarn.lock .
RUN yarn

COPY . .
RUN yarn build

# Run
FROM node:12-alpine

WORKDIR /usr/src/app

COPY --from=0 /usr/src/app .

EXPOSE 80

CMD ["yarn", "start:prod"]

Use eb-cli to init application and create an environment

eb init
eb create
eb deploy

Add environment variables

Setup RDS

Last updated

Was this helpful?