googleads
How To Deploy A Node.js App To The AWS Elastic Beanstalk
preloder
Quick Tips

How To Deploy A Node.js App To The AWS Elastic Beanstalk

 

AWS Elastic Beanstalk

Amazon Web Services (AWS) Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS. It’s the fastest and simplest way to deploy your application on AWS. It automatically handles the deployment details of capacity provisioning, load balancing, auto-scaling, and application health monitoring. Within minutes, our application will be ready to use without any infrastructure or resource configuration work on your part.

There is no additional charge for Elastic Beanstalk – it’s to be paid only for the AWS resources needed to store and run our applications.

To use Elastic Beanstalk, we need to create an application, upload an application version in the form of an application source bundle to Elastic Beanstalk, and then provide some information about the application. Elastic Beanstalk will automatically launch the environment and creates, configures the AWS resources which are needed to run the code. After creating the application, provide the information about the application—including metrics, events, and environment status which you can get through the AWS Management Console, APIs, or Command Line Interfaces, including the unified AWS CLI.

 

Steps to deploy Node.js application in AWS beanstalk

Before deploying AWS, make sure you the following things are ready in plate :

Step1: Install AWS CLI & Elastic BeanStalk CLI in your system. you can follow the below guide to install both in your system.

Installing AWS CLI 

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html

Installing Elastic BeanStalk CLI

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html

Step 2: Here am taking the Node JS sample application to use for our Deployment. If you are using Node ‘express’ framework, you can use the following ref: https://expressjs.com/en/starter/generator.html, to create an application instantly.

Step3: Create IAM User within AWS to handle deployments. Follow the below guide to create the IAM user https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html

 

Steps to Set up IAM User:

  1. AWS Access type as ‘Programmatic Access’
  2. Group assigned with ‘AWSElasticBeanstalkFullAccess’ Policy
  3. AWS Access Key ID & AWS Secret Access Key

 

Step 4: Elastic beanstalk ready AWS environment

Once these are ready, the next step is to set up Auth for AWS access.

 

Auth Setup

Auth Setup can be done by configuring AWS with the IAM user profile. Here my AWS profile name is ‘anna’. So, I configured the AWS Profile as below :

 

Creating Elastic BeanStalk Application

Elastic Beanstalk CLI tool is used to initialize our Node project as an EB project. For this purpose, we are using the ‘eb init’ command along with the IAM to create the user profile.

As we have a IAM Profile created as ‘anna’, I am using the same profile to initialize an EB CLI Project, instead of plain ‘eb init’.

  • Select a default region
  • Provide credentials (AWS access ID & AWS Secret Key)
  • Select an application to use (as we are running the commands in current nodejs project, it will be selected)
  • Select a Platform, that matches the language or framework, here ‘Node.js is our Platform
  • Then setup SSH Instances for EB environment.
  • Next, the EB CLI registers the new key pair with Amazon EC2 for you and stores the private key locally in a folder named .ssh in your user directory.

 

Click this link to know the full list for configurations available with the EB.

Setting Up Beanstalk Environment

Creating environments with EB CLI requires a service role. Service role can be created by creating an environment in the Elastic Beanstalk console. If we don’t have a service role, the Elastic Beanstalk CLI attempts to create one while running ‘eb create’.

 

 

After executing the ‘eb create’ command in our Node application directory, you can able to see ‘.elasticbeanstalk’ directory inside of our application which has a ‘config.yml’ as mentioned below :

 

 

 

This file contains enough information needed for EB to create the environment.

This link will provide detailed information on creating the EB environment through CLI.

The next step is to configure the EB to deploy our uploaded Node application on the beanstalk environment.

 

Also Read: Practical Guide To Avoid Memory Leaks In Node.js

 

Deploying Node.Js application

 

 

Before deploying your application on the beanstalk, the Node Command has to be configured with ‘npm start’ to deploy the application. Now, the beanstalk will start deploying your application and its health status now will become ‘OK’. So, it’s a sign that our application is in a good state.

 

 

Once it is done, we can able to watch our application live, using the beanstalk URL which will look like this, ie., http://ebs-node-app-dev.us-east-2.elasticbeanstalk.com/

 

This URL will hold the application name & server URL of the beanstalk.

 

In case, If you wish to make any changes on the Node application, and wish to deploy your application after that, then we can use the ‘eb deploy’ command from the console.

 

Thanks for reading! Hope you have got a clear view on deploying Node.js application in AWS Elastic Beanstalk. Do post us your queries in the comment section. We love to help you out.

 

Also read: Guide To Build An Interactive CLI Application With Node.js

 

Like What You're Reading ?

 

The following two tabs change content below.

Annamalai

Tech lead at Agira, Around 10+ years of experience in IT industry; He demonstrated numerous success in various projects by directing the team with great guidance to apply the intense logics to accomplish the goal on time. Reliable working experience in modern web technologies, especially in Node.js and always loves to reserve his time in reading magazines & travelling.

Leave a Reply

Your email address will not be published. Required fields are marked *

[contact-form-7 id="120788" title="Web Page Form"]

Schedule Your Call