Deploy Node.js Application To AWS Beanstalk With SSL and Load Balancer

A lifelong learner. Love to travel. Listen to music.
Search for a command to run...

A lifelong learner. Love to travel. Listen to music.
No comments yet. Be the first to comment.
Best Practices for Path Structure, Versioning, and Error Handling

Understanding the Performance Implications of async and defer Attributes

Overview static: Default position. It does not allow setting properties like top, bottom, left, right, z-index relative: Acts the same as static. but allows positioning it relatively by putting properties like top, bottom, left, right, z-index absolu...

Overview When an element in the browser has a conflict of styles, the browser uses a set of rules to determine which style should be rendered. This set of rules is defined as CSS Selector Specificity. For instance, for an element, if we have the foll...

Master block, inline, flex, and grid to build better web layouts

AWS Beanstalk acts as an Infrastructure as a Service (IaaS). We will deploy a node application to the AWS Beanstalk. Then we will ensure the HTTPS connection with Application Load Balancer. To make this work, we will make use of the following AWS services,
Our Architecture will be followings,

To accomplish the goal, we will go with following steps,
Node.js app in local machineElastic BeanstalkSSL certificateWe have to make sure, we have
We will deploy the code to Beanstalk manually. So we do not need the AWS CLI or Elastic Beanstalk (eb) CLI.
First, get the code from GitHub,
git clone https://github.com/socketio/chat-example.git
Go to the code repository,
cd chat-example
To install dependencies,
yarn
You may use npm instead of the yarn. In this case use npm i.
Run the app in local machine
yarn start
If you use npm, use npm start.
The server should be up and running on port 3000. Go to browser and open http://localhost:3000. This is a chat app and to verify functionalities, you may open these in two different browser windows and do messaging back and forth.
Before we go to aws console, we need to zip the source code for Elastic Beanstalk. It provides several options to deploy the code,
To make the source code zipped, we can go to the zip directory and do the zipping,
cd chat-example
zip -r chat-example.zip .
This will create a zip file named, chat-example.zip. You may manually zip the source files from the source folder.
Now go to https://aws.amazon.com and find the service Elastic Beanstalk. To create an application in Elastic Beanstalk we have to go through a couple of following steps,
Create applicationchat-exampleNode.jsUpload your codeSource code origin select the Local filechat-example.zip file we created in our local machineThis might take several minutes. When the application is created, we will find the application URL at Go to Environment.
Test the app in two different browser windows.
Before we get a certificate, we have to ensure, we have a Hosted Zone in Route 53 with a domain.
In my case, I already have a domain shams-nahid.com. I will put this application in chat-example.shams-nahid.com. So I will get the certificate for chat-example.shams-nahid.com.
So first, go the the Certificate Manager service. Request a public certificate and put the desired domain. In my case, it is chat-example.shams-nahid.com. Since my hosted zone is in AWS, DNS Validation will be faster. Confirm the request and add the DNS Resolution to the Route 53.
Click Complete and wait for validation to be completed. It may take 5-30 minutes.
Now we have a running application in Elastic Beanstalk and also have a SSL certificate we can use.
We left two steps to use SSL in the Beanstalk have,
Load Balancer to the Elastic BeanstalkRoute 53 Record to point to the Load BalancerAdd Load Balancer
To use HTTPS connection, we must make use of the Load Balancer. The Load Balancer will have a secure connection and it will route the traffic to Elastic Beanstalk.
In the Elastic Beanstalk select Environment -> Configuration -> Load Balancer settings.
Now add a listener with the following config,
Port use 443 (Default port for SSL)Protocal use HTTPSCertificate use the newly created certificateSSL Policy use the latest oneApply and wait for the application to be updated.
Go to
Elastic Beanstalkconfiguration forcapacityand make sure theEnvironment TypeisLoad Balanced.
Update Route 53 Records
Go to the Route 53 service hosted zone and add create a record,
chat-example (Since, in my case URL are chat-example.shams-nahid.com)AAliasApplication and Classic Load BalancerALB URL from the dropdownNow hit Create Record button and we are all set to go.
Go to the URL https://chat-example.shams-nahid.com and we should see the application is up and running.
You might chaek the videos on deploying app and secure connection
Please feel free to comment out any issues you are facing. I will assist accordingly.