Menu
Elastic Load Balancing
Application Load Balancers

Listener Rules for Your Application Load Balancer

The rules that you define for your listener determine how the load balancer routes requests to the targets in one or more target groups.

Each rule consists of a priority, action, optional host condition, and optional path condition. For more information, see Listener Rules.

Note

The console displays a relative sequence number for each rule, not the rule priority. You can get the priority of a rule by describing it using the AWS CLI or the Elastic Load Balancing API.

Prerequisites

A rule routes requests to its target group. Before you create a rule or update the target group for a rule, create the target group and add targets to it. For more information, see Create a Target Group.

Add a Rule

You define a default rule when you create a listener, and you can define additional nondefault rules at any time.

To add a rule using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation pane, under LOAD BALANCING, choose Load Balancers.

  3. Select the load balancer and choose Listeners.

  4. For the listener to update, choose View/edit rules.

  5. Choose the Add rules icon (the plus sign) in the menu bar, which adds Insert Rule icons at the locations where you can insert a rule in the priority order.

    
                            The Add rules icon on the menu bar.
  6. Define the rule as follows:

    1. Choose Insert Rule.

    2. To configure host-based routing, choose Host and type the hostname (for example, *.example.com).

    3. To configure path-based routing, choose Path and type the path pattern (for example, /img/*). Note that if you have already added a host condition, you must choose the ampersand (&) to add a path condition.

    4. For Forward to, choose a target group.

    5. (Optional) To change the order of the rule, use the arrows. Note that the default rule always has the last priority.

    6. Choose Save.

    
                            The Insert Rule interface.
  7. To leave this screen, choose the Back to the load balancer icon (the back button) in the menu bar.

To add a rule using the AWS CLI

Use the create-rule command to create the rule. Use the describe-rules command to view information about the rule.

Edit a Rule

You can edit the action and conditions for a rule at any time.

To edit a rule using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation pane, under LOAD BALANCING, choose Load Balancers.

  3. Select the load balancer and choose Listeners.

  4. For the listener to update, choose View/edit rules.

  5. Choose the Edit rules icon (the pencil) in the menu bar.

    
                            The Edit rules icon on the menu bar.
  6. For the rule to edit, choose the Edit rules icon (the pencil).

  7. (Optional) Modify the host and path conditions as needed. For example, you can type a new hostname for the host condition, type a new path pattern for the path condition, add a path condition if you don't have one already, add a host condition if you don't have one already, or delete a condition using the Delete condition icon (the trash can). Note that you can't add a condition for the default rule.

    
                            The Edit Rule interface.
  8. (Optional) Choose a new target group from Forward to.

  9. Choose Update.

  10. To leave this screen, choose the Back to the load balancer icon (the back button) in the menu bar.

To edit a rule using the AWS CLI

Use the modify-rule command.

Reorder Rules

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.

Note

The console displays a relative sequence number for each rule, not the rule priority. When you reorder rules using the console, they get new rule priorities based on the existing rule priorities. To set the priority of a rule to a specific value, use the AWS CLI or the Elastic Load Balancing API.

To reorder rules using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation pane, under LOAD BALANCING, choose Load Balancers.

  3. Select the load balancer and choose Listeners.

  4. For the listener to update, choose View/edit rules.

  5. Choose the Reorder rules icon (the arrows) in the menu bar.

    
                            The Reorder rules icon on the menu bar.
  6. Select the check box next to a rule, and then use the arrows to give the rule a new priority. Note that the default rule always has the last priority.

  7. When you have finished reordering rules, choose Save.

  8. To leave this screen, choose the Back to the load balancer icon (the back button) in the menu bar.

To update rule priorities using the AWS CLI

Use the set-rule-priorities command.

Delete a Rule

You can delete the nondefault rules for a listener at any time. You cannot delete the default rule for a listener. When you delete a listener, all its rules are deleted.

To delete a rule using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation pane, under LOAD BALANCING, choose Load Balancers.

  3. Select the load balancer and choose Listeners.

  4. For the listener to update, choose View/edit rules.

  5. Choose the Delete rules icon (the trash can) in the menu bar.

  6. Select the check box next to the rule. Note that you can't delete the default rule for the listener.

  7. Choose Yes, Delete.

  8. To leave this screen, choose the Back to the load balancer icon (the back button) in the menu bar.

To delete a rule using the AWS CLI

Use the delete-rule command.