Listener rules for your Application Load Balancer - Elastic Load Balancing
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

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, one or more actions, and one or more conditions. For more information, see Listener rules.

Requirements

  • Rules can only be attached to secure listeners.

  • Each rule must include exactly one of the following actions: forward, redirect, or fixed-response, and it must be the last action to be performed.

  • Each rule can include zero or one of the following conditions: host-header, http-request-method, path-pattern, and source-ip, and zero or more of the following conditions: http-header and query-string.

  • You can specify up to three comparison strings per condition and up to five per rule.

  • A forward action routes requests to its target group. Before you add a forward action, 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.amazonaws.cn/ec2/.

  2. On the navigation pane, choose Load Balancers.

  3. Select the load balancer to view its details.

  4. On the Listeners and rules tab, do one of the following:

    1. Select the text in the Protocol:Port column to open the detail page for the listener.

      On the Rules tab, choose Add rule.

    2. Select the listener you want to add a rule to.

      Choose Manage rules, then Add rule.

  5. You can specify a name for your rule under Name and tags, although it's not required.

    To add additional tags select the Add additional tags text.

  6. Choose Next.

  7. Choose Add condition.

  8. Add one or more of the following conditions:

    • Host header – Define the host header. For example: *.example.com. To save the condition, choose Confirm.

      Maximum 128 characters. Not case sensitive. Allowed characters are a-z, A-Z, 0-9; the following special characters: -_.; and wildcards (* and ?).

    • Path – Define the path. For example: /item/* . To save the condition, choose Confirm.

      Maximum 128 characters. Case sensitive. Allowed characters are a-z, A-Z, 0-9; the following special characters: _-.$/~"'@:+; &; and wildcards (* and ?).

    • HTTP request method – Define the HTTP request method. To save the condition, choose Confirm.

      Maximum 40 characters. Case sensitive. Allowed characters are A-Z, and the following special characters: -_. Wildcards are not supported.

    • Source IP – Define the source IP address in CIDR format. To save the condition, choose Confirm.

      Both IPv4 and IPv6 CIDRs are allowed. Wildcards are not supported.

    • HTTP header – Enter the name of the header and add one or more comparison strings. To save the condition, choose Confirm.

      • HTTP header name – Rule will assess requests containing this header to confirm matching values.

        Maximum 40 characters. Not case sensitive. Allowed characters are a-z, A-Z, 0-9, and the following special characters: *?-!#$%&'+.^_`|~. Wildcards are not supported.

      • HTTP header value – Enter strings to compare against the HTTP header value.

        Maximum 128 characters. Not case sensitive. Allowed characters are a-z, A-Z, 0-9; spaces; the following special characters: !"#$%&'()+,./:;⩽=>@[]^_`{|}~-; and wildcards (* and ?).

    • Query string – Route requests based on key:value pairs or values in the query string. To save the condition, choose Confirm.

      Maximum 128 characters. Not case sensitive. Allowed characters are a-z, A-Z, 0-9; the following special characters: _-.$/~"'@:+&()!,;=; and wildcards (* and ?).

  9. Choose Next.

  10. Define one of the following actions for your rule:

    • Forward to target groups – Choose one or more target groups to forward traffic to. To add target groups choose Add target group. If using more than one target group, select a weight for each target group and review the associated percentage. You must enable group-level stickiness on a rule, if you’ve enabled stickiness on one or more of the target groups.

    • Redirect to URL – Specify the URL that client requests will be redirected to. This can be done by entering each part separately on the URI parts tab, or by entering the full address on the Full URL tab. For Status code you can configure redirects as either temporary (HTTP 302) or permanent (HTTP 301) based on your needs.

    • Return fixed response – Specify the Response code that will be returned to dropped client requests. Additionally, you can specify the Content type and Response body, but they're not required.

  11. Choose Next.

  12. Specify the Priority of your rule by entering a value from 1-50000.

  13. Choose Next.

  14. Review all the details and settings currently configured for your new rule. Once you're satisfied with your selections, choose Create.

To add a rule using the Amazon 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. Rule updates do not take effect immediately, so requests could be routed using the previous rule configuration for a short time after you update a rule. Any in-flight requests are completed.

To edit a rule using the console
  1. Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/.

  2. On the navigation pane, choose Load Balancers.

  3. Select the load balancer.

  4. On the Listeners and rules tab, do one of the following:

    1. Select the text in the Protocol:Port column to open the detail page for the listener.

      1. On the Rules tab, in the Listener rules section, select the text in the Name tag column for the rule you want to edit.

        Choose Actions, then Edit rule.

      2. On the Rules tab, in the Listener rules section, select the rule you want to edit.

        Choose Actions, then Edit rule.

  5. Modify the name and tags as needed. To add additional tags select the Add additional tags text.

  6. Choose Next

  7. Modify the conditions as needed. You can add, edit an existing, or delete conditions.

  8. Choose Next

  9. Modify the actions as needed.

  10. Choose Next

  11. Modify the rule priority as needed. You can enter a value from 1-50000.

  12. Choose Next

  13. Review all the details and updated settings configured for your rule. Once you're satisfied with your selections, choose Save changes.

To edit a rule using the Amazon CLI

Use the modify-rule command.

Update rule 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.

To update rule priority using the console
  1. Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/.

  2. On the navigation pane, choose Load Balancers.

  3. Select the load balancer.

  4. On the Listeners and rules tab, do one of the following:

    1. Select the text in the Protocol:Port or Rules columns to open the detail page for the listener.

      1. Choose Actions, then Reprioritize rules.

      2. On the Rules tab, in the Listener rules section, choose Actions then Reprioritize rules.

    2. Select the listener.

      1. Choose Manage rules, then Reprioritize rules

  5. In the Listener rules section the Priority column displays current rules priority. You can update a rules priority by entering a value from 1-50000.

  6. Once you're satisfied with your changes, choose Save changes.

To update rule priorities using the Amazon 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.amazonaws.cn/ec2/.

  2. On the navigation pane, choose Load Balancers.

  3. Select the load balancer.

  4. On the Listeners and rules tab, do one of the following:

    1. Select the text in the Protocol:Port or Rules columns to open the detail page for the listener.

      1. Select the rule you want to delete.

      2. Choose Actions, then Delete rule

      3. Type confirm in the text field, then choose Delete.

    2. Select the text in the Name tag column to open the detail page for the rule.

      1. Choose Actions, then Delete rule.

      2. Type confirm in the text field, then choose Delete.

To delete a rule using the Amazon CLI

Use the delete-rule command.