Configuration of Path-based routing on Application Load Balancer in AWS.

Loknath Das
4 min readJan 6, 2021

Overview

AWS offers 3 types of load balancers as part of the Elastic Load Balancer (ELB) 1. Classic Load Balancer, 2. Network Load Balancer (TCP load balancer) and the latest is the Application load balancer (ALB).

Before diving into the configuration part, let us understand what is path-based routing, and how the application load balancer works inside AWS.

What is Path-based routing?

Path-based routing as the name indicates is related to some path, so what is this path we are talking about, well the path we are talking about is nothing but the request from the ALB to different destinations.

How does Application Load Balancer work?

Application load balancer works at the application layer i.e the 7th layer of the OSI model. after the load balancer receives a request from a user, it checks the listener rule and selects the target group. as ALB can’t take decisions based on port numbers so it has to check the 7th layer.

Example

In the image below if the request from the users contains the ( /product) inside the URL, then the request would be forwarded to the EC2 instance where all the product-based things are running. and if the URL contains (/services) then the request would be forwarded to the EC2 instance by ALB to the services.

Application load balancer architecture
Application load balancer design

Configuration of Application Load Balancer.

  1. Here we are going to launch two EC2 instances and these instances would be running the apache web server inside it. Both the instance won’t have any public IP address.

2. After launching instances we need to create a target group. to setup path-based routing we need at least two target groups. Under LOAD BALANCING, Click Target Groups, Select Create target group, Choose target type as Instances.

3. Specify a name for the target group, And the Protocol to be HTTP and port 80. Protocol version would be the default(HTTP1) after that, we have mentioned the health check path and registered the instances to it.

4. As you can see we have created two target groups here one of the target groups i.e ChatService is registered with /chat instance and the other is with /search instance.

5. Now, we need to create the Application Load Balancer. Click on the EC2 instances and then Elastic Load Balancer and click on create.

6. So now we need to configure the load balancer, firstly name your load balancer and add the port that ALB would be listening on.

7. Configure the routing, select the existing target group which we have created already. Finally, our ALB is created but now we need to create a policy/rule for our application load balancer so that it can perform the reverse proxy

8. Click on the ALB name we have just created, select the listener tab and there click on view/edit rules. here we are going to add the rule for forwarding, click on the insert rule to add the new rule.

9. Select the rule type as a path and enter /chat/*(this is the folder path in which we have our webpage) in the is, under forward to select the target group as ChatService.

Insert one more rule having rule type as a path in the is enter /search/* and for target group select SearchService.

Result

After we have these rules created, copy the DNS name of the ALB and enter in the browser with /chat/ and /service/ in the URL you can see different sites.

Thank you for reading, Feel free to drop suggestions, “Peace out”.

--

--