Github - Deploying a Nest.js App to AWS Elastic Beanstalk (Node.js Platform) with Github Actions
Steps
Push code to GitHub
Trigger GitHub Actions to
install dependencies
andbuild project
Deploy the project to AWS Elastic Beanstalk
Run script in Procfile
(npm run start:prod)
What do we need?
Procfile - Add
Procfile
to your Nest.js Application.ebignore - Add
.ebignore
to your Nest.js ApplicationPORT - Let your Nest.js Application listening port match to Elastic Beanstalk proxy forwarding port
GitHub Workflow files
Add Procfile
to the root of your Nest.js Application
Procfile
to the root of your Nest.js Applicationweb:npm run start:prod
Add .ebignore
to the root of your Nest.js Application
.ebignore
to the root of your Nest.js Application/node_modules
If.ebignore
is present, the EB CLI doesn't read.gitignore
.
This file prevents dist
folder to be ignored when deploy.
Set Environment Variable PORT
to 8080
at Elastic Beanstalk - Config
PORT
to 8080
at Elastic Beanstalk - ConfigIf your application listening to process.env.PORT, then you can set Elastic Beanstalk Config PORT to any port. Otherwise, set your application listening port to 8080 to match the default proxy forwarding port.

GitHub Workflow files
# This is a basic workflow to help you get started with Actions
name: CD
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [master]
pull_request:
branches: [master]
# A map of environment variables that are available to all jobs and steps in the workflow
env:
AWS_ENVIRONMENT_NAME: aws_environment_name
AWS_DEFAULT_REGION: ap-northeast-1
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- name: Install
run: |
node -v
yarn -v
yarn install
- name: Build
run: yarn build
- name: Deploy
uses: hmanzur/actions-aws-eb@v1.0.0
with:
command: 'deploy ${{ env.AWS_ENVIRONMENT_NAME }}'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
PreviousGithub - Deploying a Nest.js App to AWS Elastic Beanstalk (Docker Platform) with Github ActionsNextUsing Fastlane to automate beta deployments and releases for your iOS and Android apps
Last updated
Was this helpful?