Can ELB redirect request depending on the URL?

39,564

Solution 1

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.

Solution 2

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/

Share:
39,564

Related videos on Youtube

subhashlg26
Author by

subhashlg26

Updated on July 09, 2022

Comments

  • subhashlg26
    subhashlg26 almost 2 years

    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:

    1. Does ELB has ability to look into HTTP request?
    2. Can ELB redirect request depending on the URL Path Parameter?
  • Steffen Opel
    Steffen Opel over 10 years
    @AlexKliuchnikau - not that I'm aware of regarding the scope of this question - AWS recently announced Cross-Zone Load Balancing, but there are no other relevant changes surfaced in the version history of the latest release of Elastic Load Balancing on 2013-11-06 since this post.
  • Aliaksei Kliuchnikau
    Aliaksei Kliuchnikau over 10 years
    Thanks, I also came to conclusion that it is still impossible to make URL-based routing in ELB yet.
  • john
    john almost 9 years
  • skfd
    skfd over 8 years
    But does Amazon has non-ELB instrument to achieve this?
  • Shatiz
    Shatiz over 8 years
    ELB still does not support it. HAProxy could be an alternative : stackoverflow.com/questions/20606544/…
  • Steffen Opel
    Steffen Opel over 7 years
    @skfd - AWS has just launched a new Application Load Balancer option for the Elastic Load Balancing service that can redirect based on the URL, see my updated answer for details.
  • ZygD
    ZygD over 7 years
    The new ALBs don't let you switch on path or URL. They simply route based on path only and repeat that path to the underlying target group instances. If you want to combine classic ELBs (which we looked at) then you need a code change because the target code needs to listen on the path (unless you change Apache etc which we don't). The ALBs are not fit for purpose yet IMO