AWS Application Load Balancer Listener Rules and Advance Routing Options

AWS Application Load Balancer Listener Rules and Advance Routing Options

AWS Application Load Balancer listener rules and advance routing options

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to create an Application Load Balancer using AWS CLI.

https://cloudaffaire.com/how-to-create-an-application-load-balancer-using-aws-cli/

In this blog post, we will discuss AWS ALB listener rules and different routing options available in ALB.

AWS Application Load Balancer listener rules and routing options:

Listener Rules:

Each listener has a default rule, and you can optionally define additional rules. Each rule consists of a priority, one or more actions, and one or more conditions. You can add or edit rules at any time

Default Rules:

When you create a listener, you define actions for the default rule. Default rules can’t have conditions. If the conditions for none of a listener’s rules are met, then the action for the default rule is performed.

Rule Priority:

Each rule has a priority. Rules are evaluated in priority order, from the lowest value to the highest value. The default rule is evaluated last. You can change the priority of a nondefault rule at any time. You cannot change the priority of the default rule.

Rule Conditions

Each rule condition has a type and configuration information. When the conditions for a rule are met, then its actions are performed.

Rule Condition Types:

  • path-pattern: Route based on path patterns in the request URLs.
  • source-ip: Route based on the source IP address of each request.
  • host-header: Route based on the host name of each request.
  • http-header: Route based on the HTTP headers for each request.
  • http-request-method: Route based on the HTTP request method of each request.
  • query-string: Route based on key/value pairs or values in the query strings.

Rule Actions:

Each rule action has a type, an order, and the information required to perform the action.

Rule Action Types:

  • fixed-response: Return a custom HTTP response.
  • forward: Forward requests to the specified target groups.
  • redirect: Redirect requests from one URL to another.
  • authenticate-oidc: [HTTPS listeners] Use an identity provider that is compliant with OpenID Connect (OIDC) to authenticate users.
  • authenticate-cognito: [HTTPS listeners] Use Amazon Cognito to authenticate users.

AWS Application Load Balancer listener rules and advance routing options demo:

Step 1: Create a custom VPC and EC2 instances for your ALB.

Step 2: Create your Application Load Balancer

Step 3: Create a listener for your ALB with a default fixed response rule.

AWS Application Load Balancer Listener Rules and Advance Routing Options

Note: Default rule does not support any conditions.

Step 4: Create a custom rule with fixed response action and host header condition.

Step 5: Create a custom rule with fixed response action and http header condition.

Step 6: Create a custom rule with fixed response action and http request method condition.

Step 7: Create a custom rule with fixed response action and source IP condition.

Step 8: Create a custom rule with redirect action and query string condition.

Step 9: Create a custom rule with forward action and path condition (also known as path-based routing).

AWS Application Load Balancer Listener Rules and Advance Routing Options

Step 10: Cleanup

Hope you have enjoyed this article, In the next blog post, we will discuss target groups for Application Load Balancer.

All the public cloud providers are changing the console user interface rapidly and due to this some of the screenshots used in our previous AWS blogs are no longer relevant. Hence, we have decided that from now onwards most of the demo will be done programmatically. Let us know your feedback on this in the comment section.

To get more details on AWS ELB, please refer below AWS documentation

https://docs.aws.amazon.com/elasticloadbalancing/index.html

 

This Post Has One Comment

  1. Do you have any of the rules examples in cdk using python? I’m looking for examples that will help me build
    rule for if path = /index then authenticate to cognito

Leave a Reply

Close Menu