Tech Junkie Blog - Real World Tutorials, Happy Coding!: Iaas With AWS: Create An Application Load Balancer (Routing)

Monday, November 30, 2020

Iaas With AWS: Create An Application Load Balancer (Routing)

 In the previous post we went over how to create a Network Load Balancer, in this post we are going to create one of types of load balancer AWS offers.  We are going to create a Application Load Balancer, this balancer  is designed to work best with the typical line of business web applications.  It deals mostly with the requests/response scenarios on the web, therefore it supports the HTTP, and HTTPS protocols exclusively.  It can be setup to respond to the routes that configured or the hosts.  It all depends on how your web applications serves the client.  In a way it's the easiest load balancer type to understand because it deals with headers, URLs,  routes,  parameters, query strings and etc.

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 four 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
cd /var/www/html/
cp index.html contacts.html

We just created an index.html file to write out the hostname for testing later on, we also created a new file called contacts.html so that we can have different routes.

To create more than one instance at a time, type in the number of instances in the "Number of Instances" field.  Select no preferences for the subnets

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

3. On the create the four 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 there's a contacts.html page that you can route to in the load balancer based on the URL, that's the difference between the Application Load Balancer and the other two load balancers. It specializes more with web technology.

3. So now we want to create two target groups, one that serves up index.html, and the other one serving up contacts.html
So on the EC2 Dashboard under "LOAD BALANCING" click on "Target Groups"

Give your target group a name, select "HTTP" as the protocol, "Target type" is "Instance", this target group will route to the index.html page.

Click "Next" until you get to the "Register targets" page. Register two of the instances. Then click on "Create target group"

4.  Create another target group with the same setting, but give it a different name, but this time register the other two instances.

Now its time to create the Network Load Balancer

3. 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 "Application Load Balancer" by clicking on the "Create" button

4.  On the next page give your load balancer a name and select "internet-facing" for the "Scheme", for Listeners accept the default which is HTTP on port 80

5.  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

5. For Security Group settings select or create a Security Group with HTTP traffic

6.  In the "Step 4: Configure Routing" you have to specify the target group for your Appliation Load Balancer.  Assign the first target group ta the "Target group" we can assign the instances we created. Accept the default because we want to protocol to be HTTP and port 80 still.  Then click "Next"

Accept the "Register targets" for the group

8. Click "Next" until you get to the "Create" button and click on "Create"

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

9. Once the Application Load Balaneer has been created click on the "Listeners" tab you will see that currently there's one listener than routes traffic to target group one, which will route traffic to the / route.  Which is index.html, we want to create another rule to route traffic to route /contacts.html and assign it to the second target group.

10. In order to direct traffic to the second target group, click on "View/edit rules" link, click on the "+" icon, then click on the "+ Insert Rules" link, then click on the "Add Condition" button.  Then choose "Path"

11.  In the "Path.. is" field, type /contacts* then click on "+Add action" then select "Forward" to

12. Select the second target group, then click "Save"

13. Now we have two groups defined, one for index.html and the other one for contacts.html

14.  Now if we go the load balancer we should get two different instances when we browse to /, which is index.html and /contacts.html

Previous: Iaas With AWS: Create A Network Load Balancer


  1. This is an amazing article you have shared... I really like how you have detailed everything so good

    That's Great & Giving so much information after reading your blog.For RentaPC : Laptop on Rent | PC | Tablets | Macbooks
    Great thanks to you
    Laptop on Rent
    Latest News

    BT Mail

  3. This page contains the necessary information I have a enjoyable site if you feel free you can visit my site Yespornplease

  4. This page contains the necessary information The Samsung Galaxy M52 is going to be published very soon if you feel free you can visit my site Samsung M52 Price

  5. 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 email belgie

  6. 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

  7. 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

    This is a very helpful article plz read it

  9. is a very helpful article plz read it

  10. This is so informative content, you don't know how helpful for me this blog.Thank you. Need a business identity click below:
    custom logo design services


Search This Blog