13

E.g. I have two backend services, A and B, and I want to forward everything with path

/A* to A and /B* to B - but I want to strip out the /A/ and /B/ before it hits them. So for example /A/api reaches A as /api. Is this possible?

Edit: I specifically want to forward the traffic, not redirect.

Andrew
  • 6,295
  • 11
  • 56
  • 95
  • i am also having same problem. have you able to achieve this? if yes, please let me know./ – Hasitha Nov 13 '20 at 06:45
  • I face the same problem. AWS ALB still doesn't support path rewriting in 2022. For now I have to use `/A/api` and `/B/api` in all my apps. – chehsunliu Jun 28 '22 at 08:31
  • is there any proper way to accomplish this? – c.uent Jul 29 '22 at 15:55
  • did you find a solution? Is there a solution to this? For now what I did as a workaround is calling the full path and adding `/v1/api/b_request`. However, the disadvantage is that it calls a specific method only. I've been thinking if combining the ALB with an API Gateway would fix the problem. – c.uent Aug 01 '22 at 13:05
  • Does this answer your question? [AWS ELB rewrite path and alter the path in between](https://stackoverflow.com/questions/53157427/aws-elb-rewrite-path-and-alter-the-path-in-between) – qfwfq Sep 02 '22 at 22:17

3 Answers3

1

If your services are separated servers:

  1. Create target group for service A (target_A)
  2. Create target group for service B (target_B)
  3. Add servers to their groups.
  4. Create balancer path rule "If Path is /A/* THEN Forward to target_A: 1 (100%)"
  5. Create balancer path rule "If Path is /B/* THEN Forward to target_B: 1 (100%)"
Vlad
  • 417
  • 5
  • 13
  • had a question here, Suppose we have a paths like `user/explore` and we want to call the service with just `explore`. Is there a way to change the path? – Ash Jan 15 '21 at 10:58
  • It can be done through webserver settings. For example, Apache webserver has "mod_rewrite" module for this purposes. – Vlad Jan 15 '21 at 12:20
1

I don't think it's possible, what worked for me is simply configuring my backends so that locally I can start them without the context, and then when deployed, a context is added.

JFCorleone
  • 623
  • 6
  • 18
0

I think you can do redirect rewrite rule, this content is for forcing https redirection but I am assuming you can do a redirect to a diff url as well:

https://aws.amazon.com/premiumsupport/knowledge-center/elb-redirect-http-to-https-using-alb/

YankTHEcode
  • 634
  • 4
  • 8
  • Sorry, I was not specific enough in my question. I want to forward the traffic, not redirect it (so I can just use one cert on the load balancer for HTTPS traffic) – Andrew May 03 '20 at 04:25
  • It’s related just like there is a redirect to action there is a forward action that you can choose. Look at the last section here: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/tutorial-load-balancer-routing.html – YankTHEcode May 03 '20 at 04:48