Can ELB redirect request depending on the URL?
I am trying to set up my application server behind the Amazon Elastic Load Balancer. I am thinking to have one server dedicated for old version, and all other server dedicated for new version. I am thinking to implement this using version id in path parameter
e.g.
Current Version (3.0) : http://example.com/APPNAME/service
Old Version (2.2) : http://example.com/APPNAME/v2.2/service
I would like to know:
- Does ELB has ability to look into HTTP request?
- Can ELB redirect request depending on the URL Path Parameter?
Update 2017-04-05
After launching the new Application Load Balancer with path-based routing support last summer (see preceding update), AWS has now also added Host-Based Routing Support for AWS Application Load Balancers:
[...] You can now create Application Load Balancer rules that route incoming traffic based on the domain name specified in the Host header. Requests to api.example.com can be sent to one target group, requests to mobile.example.com to another, and all others (by way of a default rule) can be sent to a third. You can also create rules that combine host-based routing and path-based routing. This would allow you to route requests to api.example.com/production and api.example.com/sandbox to distinct target groups.
Update 2016-08-11
AWS has just (Aug 11, 2016) launched a new Application Load Balancer for the Elastic Load Balancing service, which is designed to improve flexibility and performance of real-time applications, microservices, container-based architectures, and streaming applications:
This new load balancer, which also supports the WebSocket protocol and HTTP/2, operates at the application layer and provides content-based routing support. This allows the Application Load Balancer to route requests across multiple services or containers running on one or more Amazon Elastic Compute Cloud (Amazon EC2) instances, helping to reduce costs and simplify service discovery. [emphasis mine]
As emphasized in the introductory blog post, this new Application Load Balancer option for ELB [...] runs at Layer 7 and supports a number of advanced features [whereras] the original option (now called a Classic Load Balancer) is still available to you and continues to offer Layer 4 and Layer 7 functionality.
More specifically ELB now supports the scenario at hand, because each Application Load Balancer allows you to define up to 10 URL-based rules to route requests to target groups (AWS plans to give you access to other routing methods over time).
Initial Answer
This is not possible - Amazon ELB mainly (but see below) provides Transport-layer load balancing (OSI layer 4), which bases its load balancing decisions solely on the TCP connection but ignores the application payload. The latter would allow Application-layer load balancing (OSI layer 7), where the application payload is taken into account for the load balancing decisions indeed.
The default configuration in Amazon ELB actually provides basic application level support for HTTP/HTTPS/SSL (e.g. terminating SSL connections and inserting X-Forwarded-*
headers), but you cannot adjust this configuration; put another way, ELB does look into the HTTP request here indeed, but you have no control over the ELB behavior n this regard.
This is explained in more detail within Choosing Listeners for Your Load Balancer, e.g.:
Using TCP/SSL (Layer 4) with Elastic Load Balancing
When you use TCP for both front-end and back-end connections, your load balancer will forward the request to the back-end instances without modification to the headers. This configuration will also not insert cookies for session stickiness or the X-Forwarded-* headers.
[...]
Using HTTP/HTTPS (Layer 7) with Elastic Load Balancing
When you use HTTP (layer 7) for both front-end and back-end connections, your load balancer parses the headers in the request and terminates the connection before re-sending the request to the registered instance(s). This is the default configuration provided by Elastic Load Balancing.
[emphasis mine]
The Architectural Overview provides an illustration and more details as well.
It's been years since you posted your question, but Amazon has recently announced Application (Layer 7) Load Balancing Functionality. This should support what you're looking for.
Basically, you can define different target groups to which traffic is routed based on a "rule" (e.g., URL path pattern). Rules can be prioritized as needed.
See details at https://aws.amazon.com/elasticloadbalancing/applicationloadbalancer/