47

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?
Zanon
  • 29,231
  • 20
  • 113
  • 126
subhashlg26
  • 993
  • 1
  • 11
  • 25

3 Answers3

53

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.

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
  • @AlexKliuchnikau - not that I'm aware of regarding the scope of this question - AWS recently announced [Cross-Zone Load Balancing](http://aws.amazon.com/about-aws/whats-new/2013/11/06/elastic-load-balancing-adds-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](https://aws.amazon.com/releasenotes/6367791205708392) since this post. – Steffen Opel Dec 26 '13 at 15:30
  • 2
    Thanks, I also came to conclusion that it is still impossible to make URL-based routing in ELB yet. – Aliaksei Kliuchnikau Dec 26 '13 at 17:03
  • it's helpful link with http://nginx.com/blog/using-ngnix-amazon-elastic-load-balancer-aws/ – john Jun 21 '15 at 07:51
  • 1
    But does Amazon has non-ELB instrument to achieve this? – skfd Dec 16 '15 at 22:40
  • ELB still does not support it. HAProxy could be an alternative : http://stackoverflow.com/questions/20606544/haproxy-url-based-routing-with-load-balancing – Shatiz Dec 18 '15 at 20:05
  • @skfd - AWS has just launched a new [Application Load Balancer option for the Elastic Load Balancing service](https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/) that can redirect based on the URL, see my updated answer for details. – Steffen Opel Aug 12 '16 at 08:39
  • 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 – gbn Aug 15 '16 at 06:40
3

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/

jstell
  • 696
  • 7
  • 12
0

Here is a possible solution I've seen. It's not as ideal as using native Nginx Plus for load balancing but if you need to use ELB, it works.

Lets imagine an architecture like this:

                        ELB
                         |
          Server 1    Server 2   Server...
          (Current)   (Current)  (Current)
              \           |         /
                      Server X
                      (Legacy)

Each of the servers in the first layer run the "current" implementation. They also run Nginx or Apache as a web server (this is generally a best practice in front of any web app, IMO) in front of the app layer.

Each of the Nginx/Apache config files contains a line checking for the URL parameter indicating this is a legacy call which proxies the request to Server X. If it's not a legacy call it just continues the request to the "current" app.

The downside is that you're using a few cycles in the current servers to proxy to the legacy server but your architecture is quite simple and you have a centralized flow.

Matt Wielbut
  • 2,584
  • 25
  • 29