17

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?

luk2302
  • 55,258
  • 23
  • 97
  • 137
Andrew Guthrie
  • 171
  • 1
  • 1
  • 3
  • 5
    I just noticed this at the bottom: "Note that the path pattern is used to route requests but does not alter them. For example, if a rule has a path pattern of /img/*, the rule would forward a request for /img/picture.jpg to the specified target group as a request for /img/picture.jpg." The path forwarding is the issue, since I'm trying to use the path to then send the request to an alternate port, but I was hoping to strip off the path in 1 of the cases and not for the other. Anyone aware of how to do this? – Andrew Guthrie Jul 21 '17 at 13:29
  • I don't know how to do this; but I'd love to. I'm running into the same problem right now. Trying to forward `/jenkins*` to the login page of a jenkins container, `/grafana*` to the grafana login, etc. However, every request with an extension falls through to the default and then usually fails or returns a 404. Port based listeners work fine. Thoughts on how to deal with this? – Mr.Budris Sep 21 '17 at 20:59
  • @Mr.Budris resolve this issue? Same status 404 here =/ Thanks. – Diego Borges Nov 28 '17 at 13:30
  • 1
    @DiegoBorges yep -- run NGINX on a conatiner ;) But really, it's better suited to breaking out these kinds of services, as it offers robust routing and url rewriting. – Mr.Budris Nov 28 '17 at 22:24
  • Did you use ALB or ELB? I am using ALB and I don't see any path based routing on AWS console – Jun Oct 01 '21 at 00:15

2 Answers2

4

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.

Master_Yoda
  • 1,092
  • 2
  • 10
  • 18
0

I would flip both rules from their respective positions I.e make expressapp2 rule #1 and express app rule #2 for it to work like you want it to.

The ALB evaluates these rules in order of priority and even though the context path is expressapp2 it still matches expressapp and the first rule is evaluated.

user2062360
  • 1,323
  • 5
  • 16
  • 29