Deploying my Node.js Selfie App with AWS Elastic Beanstalk

Li-Ting Liao
Dev Diaries
Published in
6 min readSep 3, 2020

Goal

Recently I’m exploring how to deploy my app to a different platform. Here’s how I build and deploy a Selfie App (built with Node.js) on Heroku. It’s great to see my app working on a cloud platform and allow me to share how it works with other people so much easier.

My app is quite simple, so maybe it wouldn’t make too much difference when it comes to using different platforms to deploy. This article is to showcase how easily we can deploy our app to AWS this sort of cloud service platform.

https://railsware.com/blog/heroku-vs-aws-which-paas-hosting-to-choose/

I think the key differences between Heroku and AWS are:

  • Heroku can meet low computational demands whereas AWS can meet higher ones.
  • Heroku is suitable for Startups, small businesses while AWS can scale up to larger enterprises (with some exceptions).
  • Heroku is easier to start with but AWS is quite complicated (at least for myself :D).
https://www.opcito.com/blogs/build-your-ci-cd-with-aws-codepipeline-and-elastic-beanstalk/

Here I will showcase how to CI/CD (mainly continuously deploy) from connecting my Github to AWS CodePipeline, and Elastic Beanstalk.

In short, whenever I commit any changes to my GitHub repo, AWS CodePipeline will kick in and start the deployment process. CodePipeline will set up my app in Elastic Beanstalk the webserver. Eventually, my app will live on EC2 behind the scene.

So, let’s get started.

Giphy

Here’s my repo on Github.

Create an AWS account if not having one yet.

Now I’m using the Free plan.

Once logged in, I started with setting up an environment at Elastic Beanstalk first. Since it was my first time using the service, I need to search it:

Inside I can create a new application with a default single-instance environment (with a free tier). On the top right corner, we’re free to choose an instance that’s closer to our current location. I used Ohio but later on, I switched to Tokyo, and it is way faster :D

Create a web app with any name we want:

Here it will deploy my app with the below environment setting. I’m deploying Node.js so the setting looks like below. It will then start an environment with a Sample application for me. I will use the build pipeline to upload my actual app later on:

Hit Create application and it will take a few minutes to set up:

So far, I created a Node.js environment and a sample app inside the environment with Elastic Beanstalk. Elastic Beanstalk will automatically finish the deployment process with S3 and EC2 instances behind the scene.

Once the app environment is setup, we will see a dashboard:

Click on the demo URL to make sure the environment is working:

Now I can go to CodePipeline to create a pipeline. Click on the Services tab, and search for CodePipeline (only when we’re using it the first time):

Create Pipeline and leave the default setting as it is:

On the next page, we can choose Github as the source provider. When we first time connects our AWS account with Github, it will ask for OAuth. We won’t need to do it again for the same account:

Once connected, I chose my repo and branch, also chose to automatically link Github to my CodePipeline. So, whenever there’s commit and merge, these Github webhooks will automatically generate a new pipeline on AWS:

Here I skip the build stage:

Lastly, make sure my Elastic Beanstalk and CodePipeline are both in the same region e.g. both in Ohio (or Tokyo):

Verify all looks good, then hit create pipeline:

Here I can see my pipeline is setting up:

Normally, if you follow your setup along till this point, your pipeline should be set up just fine, and you will see your app up and running.

But mine shows below error. In case you have a similar error, just keep reading :D

It’s telling me to find this log file eb-engine.log to double-check:

I needed to go back to the Elastic Beanstalk page. Under my environment, click Logs to request either full logs or the last 100 lines. I recommended to just use last 100 lines, which is not only shorter, it will pop up in a new tab on your browser:

Found the log:

It seems that my error happened here — my environment doesn’t recognize my specified Node.js setting:

If you have taken a look at my repo in the previous article, in my package.json file, you’ll see I had an engine setting like below because I needed it to deploy the app on Heroku:

https://github.com/ting11222001/SelfieApp/blob/master/package.json

After I took that out, the environment successfully set up a Node.js version for my app, and pipeline was created:

Click on the link AWS Elastic Beanstalk below Deploy:

Click on the URL and you will see your web app is up and running on the server!

Mine looks like this, a bit awkward though…

It’s because the package I’m using in the app needs to be used under HTTPS:

And HTTPS only supports those who have their domain names or those who are using load balancers on Elastic Beanstalk which is not on my free plan.

I may have a follow-up article to get around with this. Stay tuned!

That’s all for today. Have a wonderful day ahead!

--

--

Li-Ting Liao
Dev Diaries

Software developer by day, amateur writer by night. Passionate about both code and creativity, and always seeking new ways to learn and grow.