[33/100] #100DaysOfCloud Today, I created a path-based routing on an Application Load Balancer where it routes to different web pages based on the path in the URL.
A path-based routing on an Application Load Balancer where the default routing is to a target group named main with two instances assuming it as the instances that host the main page. There are two other target groups names football and cricket with two instances each assuming these two are instances that hosts for football and cricket page. When the ALB url has a path '/football' or '/cricket', it routes it to the football or the cricket webpage respectively.
I had tried to do this a few times but always ended up getting some sort of errors. The webpage never loaded when I add the path to the url. I tried to figure out and solve it but always failed and ended up doing something else as I was short on time. Today, I decided to do it no matter what and find the problem.
I figured that if the instances in the target group that are routed based on path have their index.html file in a directory named after the path name in /var/www/html, then it works perfectly.
For example, I have a target group that routes based on path value '/football'. I created a directory in /var/www/html named football and moved the index.html file to that directory.
- Each listener has a default rule, and you can optionally define additional rules. Each rule consists of a priority, one or more actions, and one or more conditions. You can add or edit rules at any time.
- You can use forward actions to route requests to one or more target groups. If you specify multiple target groups for a forward action, you must specify a weight for each target group. Each target group weight is a value from 0 to 999. Requests that match a listener rule with weighted target groups are distributed to these target groups based on their weights.
- You can use path conditions to define rules that route requests based on the URL in the request (also known as path-based routing). The path pattern is applied only to the path of the URL, not to its query parameters.
For more information on Listeners rules and other types of routing for your Application Load Balancers, check out this documentation
You can try do it by yourself by following the steps from the link below: GitHub
Top comments (0)