Using AWS Elastic Beanstalk to deploy your Node JS app

I had the chance to finally work on a Node JS application at work (it has always been for fun and on side projects). One of the requirements for hosting was to use AWS. So in our prior projects at work we usually setup an EC2 instance and begin the environment setup. For this particular project I was the lead developer.

My experience with setting up EC2 instances were mostly deploying .NET applications and PHP applications. I had no experience setting up Node JS applications on a cloud environment yet alone professionally for clients. I was either working locally or using Heroku.

I began setting up the EC2 instances following articles I found Googling. I wasn't satisifed and it was scaring me that I had to manually install Node JS, Express JS, AWS SDK, Handlebars (I prefer that over EJS), etc. I know it's just a matter of a bunch of command lines, but this is not something I want to manage. I would also have to setup the Node server to run even after I log off the server.

I kept Googling to find the best way to deploy a Node JS application on an EC2 instance and then I kept seeing "Elastic Beanstalk" appearing. At first I ignored it becauser I had never heard of it and was afraid to try something new for this project. I accidently clicked on the AWS Elastic Beanstalk documentation on deploying Node JS applications and ended up reading it. I was fascinated by this service. It was very similar to Heroku. So I decided to spend some time and give it a try and it worked out perfect. Didn't have to worry about the server configuration or standing up an EC2 instances.

Here's how I did it.

Step 1: Install EB CLI

I used homebrew to install this:

brew install awsebcli  

Step 2: Initialize and setup the EB app deployment

To begin the setup of your EB app to be deployed you start with this command:

eb init  

It will then ask you several questions regarding the name of the app, the type of app (it should say Node JS), and which location on AWS you want to deploy it too. It will also ask you if you want to use SSH to connect to your instances.

Once you finish answering the questions you can then run:

eb create  

Step 3: Deploy the app

After the EB instance is created you can then deploy it with the following command:

eb deploy  

Your app will now be deployed on AWS. If you want to open the URL to your app you can run this command:

eb open  

It will then open the URL which may look like: YOURAPPNAME.elasticbeanstalk.com.

If you want to redeploy with new code all you have to do is run the same deploy command:

eb deploy  

Make sure all your updates have been committed. Elastic Beanstalk looks at your source control and won't deploy any uncommitted code.

tl;dr - AWS Elastic Beanstalk is very straightforward and easy way to deploy your Node JS application.