Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Application Load Balancer (ALB) path based routing not functioning as expected

I am working on a POC to prove out AWS path based routing through an Application Load Balancer to a set of very basic "hello world" node.js applications using express. Without the path based routing in place and having multiple listeners, 1 listener for each application, each respective listener and application is working as expected. Therefore, the targets within the Target Groups have both passed health checks and are shown as healthy. However, when I switch to the path based routing implementation on 1 of the listeners (deleting the other unnecessary listener) I get the following error for both applications:

Cannot GET /expressapp
Cannot GET /expressapp2

Listener Rules

I have gone through the following documentation to try to figure out the issue: http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#path-conditions

What am I missing? Any troubleshooting ideas?

like image 454
Andrew Guthrie Avatar asked Jul 20 '17 13:07

Andrew Guthrie


People also ask

Does ALB support path-based routing?

Application Load Balancer offers unique features over Classic ELB and one of the features is Path-based Routing. ALB forwards the incoming requests to different destinations based on the path you mention in the uri.

How do I achieve path-based routing on an application load balancer?

Test path-based routing To test this routing, copy the DNS name of your Application Load Balancer in a web browser and add the URL path /svcA or /svcB. When the Application Load Balancer listener receives the request, the listener forwards that request to the appropriate target group based on the path condition.

Does ELB support path-based routing?

Overview. AWS offers 3 types of load balancers as part of Elastic Load Balancer (ELB) service one is called Classic Load Balancer, TCP load balancer and the latest is the Application load balancer (ALB). ALB offers some unique features over Classic ELB and one of the features is Path-based Routing.

Why load balancer is not working?

If the load balancer is not responding to requests, check for the following issues: Your internet-facing load balancer is attached to a private subnet. You must specify public subnets for your load balancer. A public subnet has a route to the Internet Gateway for your virtual private cloud (VPC).


1 Answers

I believe that you are getting this error because the services in question do not expect to receive paths prefixed with /expressapp and /expressapp2. When the ALB forwards traffic to your service, the path remains intact.

Stripping off the prefix cannot be handled by ALB. If you don't have access to the source code of the apps, you will need to use some kind of reverse-proxy like nginx to rewrite the urls before sending them onto the app.

If you have access to the source code, express supports changing the base url without modifying the code. You can read a value for the url prefix in as an environment variable and configure your respective service environments accordingly.

like image 61
Master_Yoda Avatar answered Nov 15 '22 20:11

Master_Yoda