Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS ELB rewrite path and alter the path in between

I'm using an ELB (Elastic Load Balancer) on Amazon Webservices (spezifically an Application Load Balancer).

The Problem: I want to create a rule to rewrite the path, but need to insert a string within the path.

When a request is coming in to:

example.org/api/foo/*

I need it to be redirected to:

example.org/api/v1/foo/*

The rest of the request needs to stay the same. The problem is that the original value of path cannot be altered. One way of cause would be to add every possible path as a rule. But when expanding the api it would be extremly uncomfortable.

like image 924
Willie Avatar asked Nov 05 '18 15:11

Willie


1 Answers

Rewriting is not supported by the ELB as you already discovered.

Some options:

1) Implement a webserver e.g. nginx between the ALB and your application, which can implement rewrite rules

2) Path-based rewriting can be achieved by using Route53 -> CloudFront -> Lambda -> ALB, instead of straight up Route53 -> ALB, as demonstrated here.

like image 55
Tiemen Avatar answered Sep 28 '22 18:09

Tiemen