AWS ALB — Advanced Request Routing

Shailender Choudhary
4 min readSep 13, 2020

--

Application Load Balancer provides a mature solution for layer 7 load balancing of HTTP and HTTPS traffic. It supports request routing based on HTTP headers, HTTP methods, HTTP query parameters and source IP CIDRs in addition to the host header and path-based routing.

The ability to route based on any field in an HTTP request provides the utmost flexibility in segmenting HTTP request traffic to control the processing environment for each category of request.

Query parameters based routing

Query parameters are used along with the path component of the URL for applying a special logic to the resource being fetched. Routing based on query parameters can be used for A/B testing, Canary releases and blue-green deployment.

Whenever query parameters in the query string match the key-value pair that is provided as an input including any wildcards a successful match occurs. In fact, multiple query parameters can be used route requests to different target groups.

For example, query parameter “theme=bright”, the Application Load Balancer returns the page of a bright theme. Similarly, using ”theme=dark” in the request query parameter returns the same web page of a dark theme.

Query parameters based routing

HTTP method based routing

HTTP method based routing simplifies design of REST APIs where the same URL (/path) can be routed to different services based on the HTTP method ( GET /path -> service1, POST /path -> service2).

HTTP defines a set of request methods to indicate the desired action to be performed for a giver resource. Whenever exact match of HTTP name method which is provided by the user is matched, load balancer selects the desired target group.

In this example, two routing rules configured on the Application Load Balancer.
Rule1: ALB returns a fixed response static page for any GET requests for path /arr_method.
Rule2: Routes any POST requests for path /arr_method to a Lambda target group.

HTTP method based routing

Client IP CIDR based routing

Client IP CIDR based routing is used to allow or block web requests based on the IP addresses that the requests originate from. The rule applies to IP addresses specified in the CIDR format.

Responses for clients based on their IP covers use cases like:
1. Blacklisting/whitelisting a specific set of IPs
2. Respond with fixed content for a specific set of IPs or CIDRs.
3. Provide differentiated authentication flow for a specific set of IPs.

In this example, rules are created for single IP address CIDR 18.207.142.48/32 where “Welcome Page” is displayed while accessing the admin page and for any other CIDR, error page will be displayed.

Client IP CIDR based routing

HTTP Header based routing

ALB provides the ability to route traffic based on the fields in HTTP request header which provides flexibility in segmenting HTTP request traffic to control the processing environment for each category of request.

The most common use cases are serving mobile users with low-resolution video and desktop users with high-resolution video. Similarly, creating target group to serve requests from some legacy clients.

In this example, four routing rules are configured on the Application Load Balancer which route request to different target groups based on the User-Agent header (Chrome, Firefox, Safari, IE and Edge). Different pages are served by the Application Load Balancer whenever the page is accessed from the browsers listed above.

HTTP Header based routing

A single Application load balancer can serve most of the application’s routing unless service limit quotas are hit. Advanced request routing is available in all AWS regions at no extra charge.

Follow me on Linkedin for more articles. https://www.linkedin.com/in/shailender-choudhary-78740019/

--

--

Shailender Choudhary
Shailender Choudhary

Written by Shailender Choudhary

Lead Cloud and DevSecOps Consultant at SoftwareONE Australia

Responses (2)