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

Monday, December 7, 2020

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

 In the previous post we went over how to create a Application Load Balancer, based on routes in the URL.  In this post we are going to change the rules so that it directs traffic based on host names.  For example we could have acmebanking.com route to target group 1 and accounts.acmebanking.com route to target group 2.  It's the same concept as the previous setup but instead of routes, we are using hostnames instead.

In order to implement this solution we need to setup a record in Route 53, which is AWS domain registration service.  You can follow along with the DNS names, but if you have a hostname registered with AWS that's even better.

1. So the first thing you want to do is go to Route 53 dashboard, go to Hosted Zones

2. Click on the hosted domain



3. Click on "Create Record" button, to create an A record

An A record is basically an alias record that points to the underlying IP address, for example an A record of acmebanking.com points to some IP address.  If a browser sends a request to acmebanking.com, it is directed to the server with a particular IP address.

4. Select "Simple Routing", then click "Next"


5.  Select "Define simple record"




6.  We want to create two A records, one is the root domain record acmebanking.com and the other A record will be accounts.acmebanking.com.  First lets create the root record, leave the "Record name"  field blank so that the alias is just acmebanking.com.  Then route the traffic to the Application Load Balancer we created in the previous post. Then click on "Define simple record"


You should see the following if you are following along



7. Create another A record, but this time type accounts in the "Record name" field so the alias will be accounts.acmebanking.com, then click on the "Define simple record" button. 

You should see the following A records, select both records and click on "Create records"


Now these records are created, which points to the load balancer.


8.  Now you want to add a rule to the load balancer to direct traffic to target group 2 if the hostname is accounts.acmebanking.com.  So go to the load balancer and click on the "View/edit rules"

9. Click on the + sign next to "Rules", click "+ Insert Rule", "+ Add condition", "Host header"



11.  The rule should look like the following, it basically says if the hostname is accounts.acmebanking.com direct traffic to target group 2, else direct traffic to target group 1 if it's the root hostname. Click "Save"


12. Final rules should look like the following


Now if you type acmebanking.com you should get a different instance from accounts.acmebanking.com because they target different target groups.




2 comments:

Search This Blog