You can create forwarding rules for an ALB listener to control how requests are distributed to one or more backend servers.

Background information

You can create an inbound or outbound forwarding rule for an ALB listener. Each forwarding rule consists of one or more conditions and one or more actions. Architecture
Note For more information about regions that support outbound forwarding rules, see Release notes.
  • After an ALB instance receives a request, the ALB instance distributes the request to a backend server based on a specified inbound forwarding rule. Then, the backend server returns a response to the client based on an outbound forwarding rule of the ALB instance.
    • When you create an inbound forwarding rule, you can specify only inbound conditions and actions.
    • When you create an outbound forwarding rule, you can specify both inbound and outbound conditions. However, you can specify only outbound actions in an outbound forwarding rule.
  • You must specify at least one Forward action, one Redirect action, or one Return Fixed Responses action for each forwarding rule.
    • You can specify the following inbound conditions: Domain Name, Path, HTTP Header, Query String, HTTP Request Method, Cookie, and Source IP Address.
    • You can specify the following inbound actions: Forward, Redirect, Return Fixed Responses, Rewrite, Add Header, Remove Header, Throttle Traffic, and Mirror Traffic.
    • You can specify the following outbound conditions: Response Status Code and Response Header.
    • You can specify the following outbound actions: Add Header and Remove Header.
    Note Some forwarding rules are unavailable for basic ALB instances. You must upgrade to standard ALB instances before you can configure these forwarding rules. For more information, see Modify the configurations of an ALB instance.

Prerequisites

Create a forwarding rule

After you create a listener, the system automatically creates a default forwarding rule for the listener. You can add more forwarding rules to meet your business requirements.

  1. Log on to the ALB console.
  2. On the Instances page, click the ID of the ALB instance that you want to manage.
  3. On the Listener tab, find the listener that you want to manage and click View/Modify Forwarding Rule in the Actions column.
  4. On the Forwarding Rules tab, select Inbound Forwarding Rules or Outbound Forwarding Rules and click Add New Rule.
  5. In the Add Forwarding Rules section, set the following parameters and click OK.
    Note
    • The logical operator among the values of a condition is OR. A request is forwarded if the request matches one of the values specified for a condition.
    • The logical operator among different conditions is AND. A request is forwarded only if the request matches all conditions specified in the forwarding rule.
    Parameter Description
    Name Enter a name for the forwarding rule.
    Note The name must be 2 to 128 characters in length, and can contain letters, digits, periods (.), underscores (_), and hyphens (-). The name must start with a letter. Forwarding rule names must be unique within the same listener.
    Add Inbound Condition Specify one or more of the following conditions:
    • Domain Name: Enter one or more domain names. The domain name must be 3 to 128 characters in length and can contain letters, digits, hyphens (-), and periods (.). Wildcard domain names that contain asterisks (*) and question marks (?) are supported.

      In this example, *.example.com is entered.

    • Path: Enter one or more paths.

      For example, if the URL is www.example.com/test/test1?x=1&y=2, you can set the parameter to /test/*.

    • HTTP Header: Enter the name of an HTTP header in the Key field and the value of the HTTP header in the Value field.

      In this example, the key user-agent and the value *Mozilla/4.0* are entered.

    • Query String: Enter one or more query strings in key-value pairs. The key must be 1 to 100 characters in length. The value must be 1 to 128 characters in length. The key and value can contain lowercase letters and other printable characters. You can also use asterisks (*) and question marks (?) as wildcard characters. The key and value cannot contain space characters or the following special characters: # [ ] { } \ | < > &.

      For example, if the URL is www.example.com/test/test1?x=1&y=2, you can set the parameter to x:1 or y:2.

    • HTTP Request Method: Add one or more HTTP request methods.
    • Cookie: Add one or more cookies. The key must be 1 to 100 characters in length. The value must be 1 to 128 characters in length. The key and value can contain lowercase letters and other printable characters. You can also use asterisks (*) and question marks (?) as wildcard characters. The key and value cannot contain space characters or the following special characters: # [ ] { } \ | < > &.

      In this example, the key key and the value value are entered.

    • Source IP Address: Add one or more IP addresses or CIDR blocks.
    Add Outbound Condition Specify one or more of the following conditions:
    • Response Status Code: Specify the HTTP status code in the response that is sent to the client. Valid values: 100 to 599.

      You can enter individual values or value ranges, and separate them with commas (,). Example: 200-233,301.

    • Response Header: Specify an HTTP header in the response. Enter the name of the HTTP header in the Key field and the value of the HTTP header in the Value field. You can specify multiple HTTP headers.
    Action Specify one of the following actions for each condition:
    • Forward: Select the server group to which requests are forwarded. You can add multiple server groups and enable Session Persistence for Server Groups.
    • Redirect: Select a protocol from the Protocol drop-down list, and then select a status code from the Status Code drop-down list. Enter the Domain Name, Port, and Path of the destination to which requests are directed, and then enter a query string in the Query field.
      Note
      • If you enter ${x}, the value returned in the previous response is used. Otherwise, the default value specified in each request is used.
      • For more information about HTTP status codes, see Status codes.
    • Return Fixed Responses: Enter an HTTP status code in the Status Code field, specify Response Content Type, and then enter the Response Content.
    • Rewrite: Enter the Domain Name and Path of the destination to which requests are directed, and then enter a query string in the Query field.
    • Add Header: Enter the name and value of the header that you want to add to the request. Newly added headers overwrite the existing headers in the request.
    • Remove Header: Enter the value of the header that you want to remove from the request.
    • Throttle Traffic: Enter the maximum number of requests per second. Valid values: 1 to 100000. If the number of requests per second reaches the upper limit, new requests are dropped.
    • Mirror Traffic: Select the server group to which mirrored traffic is distributed.

Modify a forwarding rule

  1. Log on to the ALB console.
  2. On the Instances page, click the ID of the ALB instance that you want to manage.
  3. On the Listener tab, find the listener that you want to manage and click View/Modify Forwarding Rule in the Actions column.
  4. On the Forwarding Rules tab, select Inbound Forwarding Rules or Outbound Forwarding Rules and then click the The Edit icon icon in the upper-right corner of the forwarding rule that you want to modify.
  5. Click Save.

Change the priority of a forwarding rule

Rules are evaluated in descending order of priority. A lower value indicates a higher priority. You can change the priority of a custom forwarding rule as needed. You cannot change the priority of the default forwarding rule.

  1. Log on to the ALB console.
  2. On the Instances page, click the ID of the ALB instance that you want to manage.
  3. On the Listener tab, find the listener that you want to manage and click View/Modify Forwarding Rule in the Actions column.
  4. On the Forwarding Rules tab, select Inbound Forwarding Rules or Outbound Forwarding Rules, change the priority of the forwarding rule by dragging and dropping the forwarding rule, and then click Save Priority Changes.

Delete a forwarding rule

You can delete the custom forwarding rules of a listener anytime. The default forwarding rule of a listener cannot be deleted. After you delete a listener, all forwarding rules of the listener are deleted.

  1. Log on to the ALB console.
  2. On the Instances page, click the ID of the ALB instance that you want to manage.
  3. On the Listener tab, find the listener that you want to manage and click View/Modify Forwarding Rule in the Actions column.
  4. On the Forwarding Rules tab, select Inbound Forwarding Rules or Outbound Forwarding Rules and then click the The Delete icon icon in the upper-right corner of the forwarding rule that you want to delete.
  5. In the message that appears, click OK.