Tech Junkie Blog - Real World Tutorials, Happy Coding!: Iaas With AWS: Create A Network Load Balancer

Monday, November 23, 2020

Iaas With AWS: Create A Network Load Balancer

 In the previous post we went over how to create a Classic Load Balancer, in this post we are going to create one of types of load balancer AWS offers.  We are going to create a Network Load Balancer, this balancer  is for websites that require high performance and low latency websites, think of streaming data.  If your website needs real time streaming data, this is probably the load balancer for you. It supports layer 4 protocols such as UDP, TLS and TCP protocols. If you need a static IP or Elastic IP assigned to your load balancer this is your only choice because the other two load balancer does not give you the option to assign Elastic IPs.

Before we create the load balancer we need to create more than one instances with a web server because we need to test that the load balancer is able to switch.

1. Create two instances with the user data to create Apache Web Servers with these commands in the User Data for instance, if you need the full instruction on how to create instances with User Data you can read this post

#Use this for your user data (script without newlines)
# install httpd (Linux 2 version)

yum update -y 
yum install -y httpd.x86_64 
systemctl start httpd.service 
systemctl enable httpd.service 
echo "Hello world from $(hostname -f)" > /var/www/html/index.html

We just created an index.html file to write out the hostname for testing later on

2. For the Security Groups setting make sure there's an inbound rule for HTTP traffic

3. On the create the two instances, if you copy and paste the public DNS or public IP into the address bar of the browser you see the hostname being printed out for the instance, so if the load balancer is successfully the request should change to a different host when a user requests the site
Now its time to create the Network Load Balancer

4. On EC2 Dashboard scroll down to "LOAD BALANCING" and click on "Load Balancers",  then click on the "Create Load Balancer" button you will be presented with three choices.  Choose the "Network Load Balancer" by clicking on the "Create" button

5.  On the next page give your load balancer a name and select "internet-facing" for the "Scheme"

6. For the "Listeners" accept the default, since HTTP is part of TCP it will accepts HTTP requests on port 80 if we choose TCP

7.  For Availability Zones you have to assign at least two AZs, so pick two AZ, select your subnets and let AWS assign the IP address for you by selecting "Assigned by AWS". click "Next: Configure Security Settings", click "Next" again

8.  In the "Step 3: Configure Routing" you have to specify the target group for your Network Load Balancer.  We  going to create a new target group, and assign the target group type to instance so that we can assign the instances we created. Accept the default because we want to protocol to be TCP and port 80 still.  Then click "Next"

9. On "Step 4: Register Targets" page, select the two instances and click on the "Add to registered" button to add the instances to the Network Load Balancer

Select "Next" until you see the "Create" button, click on the "Create button

Once the Load Balancer has been created you can copy and paste the Load Balancer's DNS into the browser's address bar and it would alternate between the two instances.  You will have to wait for a while for it to work, the instances will have a status of "healthy" when it's ready

Here is result you should get when everything is finished.

The Network Load Balancer seems to implement sticky IP by default so you will probably stay with one instance for your whole session, that's actually a good thing.  So you might not get a new instance on every request.  Don't quote me on that though.


  1. Thank you for sharing your info. I really appreciate your efforts and I am waiting for your further write ups thank you once again. And know Mimz International Merchandising Company provides services to clients to Make their Vision a Reality and to help companies to improve business performance. merchandising

  2. Hi thankyou for this great helpful information.this information is really useful at today's had easily explained whole information in a short note. Now i would like to share some information about PayPal.So If you are a Paypal user and you are facing any problem regarding to PayPal. No need to worry just simply visit on our site- paypal bellen belgie

  3. Hi your post is really appreciatable.I really thankful for this post. Here i would llike to share some information about facebook. As we know that facebook is a social trap where we connect with people in all over world. So if you are using facebook and face any technical issue that time so just visit our website. We can resolve the smallest problem on same time. For further information please visit on our website- facebook bellen belgie

  4. Hi this post is very nice.finally i got all those information whatever i really wanted to know. Thankyou for sharing this usefull information. Here I want to share the information about Dell support. As we all have been digitalied and we do multiple works together so if you face any problem or need any assist about Dell klentenservice so pleae visit over this site:- dell reparatiecentrum nummer

  5. I always appreciated your work, your creation is definitely unique. Great job

    rasmussen student portal

  6. Thanks for sharing this information, will be trying this for sure. Make sure to check below:
    custom logo


Search This Blog