paint-brush
How to Deploy Your Node.js Apps to AWS Elastic Beanstalk without EB CLIby@adebola
4,331 reads
4,331 reads

How to Deploy Your Node.js Apps to AWS Elastic Beanstalk without EB CLI

by Adebola AdeniranJune 8th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How to Deploy Your Node.js Apps to AWS Elastic Beanstalk without EB CLI? How to deploy without EBCL without EB CLi.io. The first time I deployed a node.js app to the service, I was not a fan of Clis. I love Clis but definitely not a. fan of the Elastic BeanStalk Cli.IO service. The service is a similar service to Heroku and DigitalOcean i.e it provisions a server for you without you having to do any of the. complex DevOps work yourself.

Company Mentioned

Mention Thumbnail
featured image - How to Deploy Your Node.js Apps to AWS Elastic Beanstalk without EB CLI
Adebola Adeniran HackerNoon profile picture

Let’s face it — AWS is a convoluted web of so many services and can be really difficult to wrap one’s head around. That’s certainly how I felt, the
first time I deployed a Node.js app to the service. PSA I love Clis but definitely not a fan of the Elastic Beanstalk Cli.

Compared to Heroku or DigitalOcean, AWS Elastic Beanstalk(ikr Such an interesting name!) can be a little difficult to wrap your head around but it’s probably one of the easiest AWS services to use. Elastic Beanstalk is a similar service to Heroku and DigitalOcean i.e it provisions a server for you
without you having to do any of the complex DevOps work yourself.

Prerequisites

  1. An AWS Account
  2. A functioning Node.js App in a GitHub repo
  3. A GitHub account(duhh!)

Let’s get started!

First things, first, you need an AWS account. It’s pretty complex to setup. I would advice you follow freecodecamp’s AWS Cloud Certified Associate video on setting up an AWS account.

Create an Elastic Beanstalk Application and environment

  1. Click Services > Elastic Beanstalk > Create application
  2. Enter an Application name.
  3. For the platform, Select Node.js and leave the other fields as the default.
  4. Click next and wait for the environment to be done setting up. This may take up to 2minutes.

You’d get a screen like below once it’s done.

Create a Code pipeline to automatically deploy changes

1. Your node app should be setup and already running perfectly on
localhost. My app holds a list of blogs and is an app I’m building
following the fullstack course at fullstackopen.com.

I'm using MongoDB Atlas for my database. Another thing to remember is that for your ports, you need to have them set up as

const PORT = process.env.PORT || 3001

This ensures that whatever port is being used by the server AWS gives us, is picked up by our App.

2. In your AWS console, click on Services(see the menu) > Code pipeline. We will be hooking up our GitHub to AWS so that each time we push updates, our App is automatically deployed to AWS.

3. Click Create Pipeline. Fill in the pipeline name. The role name gets filled out automatically. Then select new service role as your service role. Click next.

4. Select GitHub as source provider. Click connect to GitHub to hook up your GitHub account to AWS. Select the repo your code is in and the branch. Skip the build stage and confirm.

5. Enter your application name that you created in the Elastic Beanstalk
console and select the environment name(automatically generated from
your app name) from the list.

6. Click next > Create pipeline.

7. And that’s it. We wait for our App to deploy. Hopefully you get green screens like below.

8. If anything goes wrong, you can check the environment logs.

9. To view your Node.js application: Services > Elastic Beanstalk > Click on the App’s name under environment name. The link will be displayed under the App’s name. In my case under NodejsBlog-env. (See Image in Point 4 of the 1st section)

10. You can preview my app here.

Side Notes

There were certain issues I encountered along the way.

  • dotenv package did not work after deploying to AWS EB.
  • bcrypt package had some issues after deploying to AWS EB.