• Elastic Load Balancing

elb
  1. Help Center
  2. Elastic Load Balancing
  3. API Reference
  4. Enhanced Load Balancer APIs
  5. L7 Policy (Forwarding Policy)
  6. Adding a Forwarding Policy

Adding a Forwarding Policy

Function

This API is used to add a forwarding policy. The listener and forwarding policy determine how traffic is forwarded to backend servers.

  1. By matching the URL or domain name specified in the forwarding policy when action is set to REDIRECT_TO_POOL, the load balancer distribute the traffic to backend servers in a specific backend server group.
  2. When action is set to REDIRECT_TO_LISTENER, the HTTP listener is redirected to an HTTPS listener, and traffic is distributed to this HTTPS listener.

URI

POST /v2.0/lbaas/l7policies

Constraints

Currently, only redirects from an HTTP listener to an HTTPS listener are supported. When action is set to REDIRECT_TO_LISTENER, the listener specified by listener_id can only be an HTTP listener, and the listener specified by redirect_listener_id can only be an HTTPS listener.

The load balancer of the HTTPS listener to which traffic is redirected must be the same as that of the HTTP listener.

Request

  • Request parameters
    Table 1 Parameter description

    Parameter

    Type

    Mandatory

    Description

    l7policy

    Dict

    Yes

    Specifies the forwarding policy. For details, see Table 2.

    Table 2 l7policy field description

    Parameter

    Type

    Mandatory

    Description

    tenant_id

    String (255)

    No

    Specifies the ID of the project where the forwarding policy is used.

    The value must be the same as the value of project_id in the token.

    name

    String (255)

    No

    Specifies the forwarding policy name.

    admin_state_up

    Bool

    No

    Specifies the administrative status of the forwarding policy.

    The value can be true or false.

    This parameter is reserved and has been not used. The default value is true.

    description

    String (255)

    No

    Provides supplementary information about the forwarding policy.

    listener_id

    Uuid

    Yes

    Specifies the ID of the listener to which the forwarding policy is added.

    • When action is set to REDIRECT_TO_POOL, forwarding policies can be added to a listener with protocol set to HTTP or TERMINATED_HTTPS.
    • When action is set to REDIRECT_TO_LISTENER, forwarding policies can be added to a listener with protocol set to HTTP.

    action

    String

    Yes

    Specifies the matching action of the forwarding policy.

    The value can be one of the following:

    • REDIRECT_TO_POOL: forwards traffic to the backend server group specified by redirect_pool_id.
    • REDIRECT_TO_LISTENER: redirects traffic from the HTTP listener specified by listener_id to the HTTPS listener specified by redirect_listener_id.

    redirect_pool_id

    Uuid

    No

    Specifies the ID of the backend server group to which traffic is forwarded. The default value is null.

    This parameter is mandatory when action is set to REDIRECT_TO_POOL.

    This parameter cannot be specified when action is set to REDIRECT_TO_LISTENER.

    The backend server group must meet the following requirements:

    • Cannot be the default backend server group of the listener.
    • Cannot be the backend server group used by forwarding policies of other listeners.

    redirect_listener_id

    Uuid

    No

    Specifies the ID of the listener that forwards the traffic. The default value is null.

    This parameter cannot be specified when action is set to REDIRECT_TO_POOL.

    This parameter is mandatory when action is set to REDIRECT_TO_LISTENER, and the listener must meet the following requirements:

    • Can only be an HTTPS listener.
    • Can only be a listener of the same load balancer.

    redirect_url

    String (255)

    No

    Specifies the URL to which traffic is redirected. The default value is null.

    This parameter is reserved and has been not used.

    position

    Int

    No

    Specifies the forwarding priority. The value ranges from 1 to 100. The default value is 100.

    This parameter is reserved and has been not used.

  • Example request 1: Forwarding to a backend server group
    POST https://{Endpoint}/v2.0/lbaas/l7policies 
    
    {
        "l7policy": {
            "name": "niubiao_yaqing_api-2", 
            "listener_id": "3e24a3ca-11e5-4aa3-abd4-61ba0a8a18f1", 
            "action": "REDIRECT_TO_POOL", 
            "redirect_pool_id": "6460f13a-76de-43c7-b776-4fefc06a676e", 
            "rules": [
                {
                    "type": "PATH", 
                    "compare_type": "EQUAL_TO", 
                    "value": "/test"
                }, 
                {
                    "type": "HOST_NAME", 
                    "compare_type": "EQUAL_TO", 
                    "value": "www.huawei.com"
                }
            ]
        }
    }
  • Request example 2: Creating a redirect
    POST https://{Endpoint}/v2.0/lbaas/l7policies
    
    {
        "l7policy": {
            "action": "REDIRECT_TO_LISTENER", 
            "listener_id": "4ef8553e-9ef7-4859-a42d-919feaf89d60", 
            "redirect_listener_id": "3ee10199-a7b4-4784-93cd-857afe9d0890", 
            "name": "redirect-test"
        }
    }

Response

  • Response parameters
    Table 3 Parameter description

    Parameter

    Type

    Description

    l7policy

    Dict

    Specifies the forwarding policy. For details, see Table 4.

    Table 4 l7policy field description

    Parameter

    Type

    Description

    id

    Uuid

    Specifies the forwarding policy ID.

    tenant_id

    String (255)

    Specifies the ID of the project where the forwarding policy is used.

    name

    String (255)

    Specifies the forwarding policy name.

    admin_state_up

    Bool

    Specifies the administrative status of the forwarding policy.

    The value can be true or false.

    This parameter is reserved and has been not used. The default value is true.

    description

    String (255)

    Provides supplementary information about the forwarding policy.

    listener_id

    Uuid

    Specifies the ID of the listener to which the forwarding policy is added.

    action

    String

    Specifies the matching action of the forwarding policy.

    The value can be one of the following:

    • REDIRECT_TO_POOL: forwards traffic to the backend server group specified by redirect_pool_id.
    • REDIRECT_TO_LISTENER: redirects traffic from the HTTP listener specified by listener_id to the HTTPS listener specified by redirect_listener_id.

    redirect_pool_id

    Uuid

    Specifies the ID of the backend server group to which traffic is forwarded.

    redirect_listener_id

    Uuid

    Specifies the ID of the listener that forwards the traffic.

    redirect_url

    String (255)

    Specifies the URL to which traffic is redirected.

    This parameter is reserved and has been not used.

    rules

    List

    Lists the forwarding rules associated with the forwarding policy.

    position

    Int

    Specifies the forwarding priority. The value ranges from 1 to 100. The default value is 100.

    This parameter is reserved and has been not used.

    provisioning_status

    String (16)

    Specifies the provisioning status of the forwarding policy. The value can be ACTIVE, PENDING_CREATE, or ERROR.

    The default value is ACTIVE.

    This parameter is reserved and has been not used.

  • Example response 1
    {
        "l7policy": {
            "redirect_pool_id": "6460f13a-76de-43c7-b776-4fefc06a676e", 
            "description": "", 
            "admin_state_up": true, 
            "rules": [
                {
                    "id": "742600d9-2a14-4808-af69-336883dbb590"
                }, 
                {
                    "id": "3251ed77-0d52-412b-9310-733636bb3fbf"
                }
            ], 
            "tenant_id": "573d73c9f90e48d0bddfa0eb202b25c2", 
            "listener_id": "3e24a3ca-11e5-4aa3-abd4-61ba0a8a18f1", 
            "redirect_url": null, 
            "redirect_listener_id": null, 
            "action": "REDIRECT_TO_POOL", 
            "position": 100, 
            "provisioning_status": "ACTIVE", 
            "project_id": "573d73c9f90e48d0bddfa0eb202b25c2", 
            "id": "65d6e115-f179-4bcd-9bbb-1484e5f8ee81", 
            "name": "niubiao_yaqing-_api-2"
        }
    }
  • Example response 2
    {
        "l7policy": {
            "redirect_pool_id": null, 
            "description": "", 
            "admin_state_up": true, 
            "rules": [ ], 
            "tenant_id": "573d73c9f90e48d0bddfa0eb202b25c2", 
            "listener_id": "4ef8553e-9ef7-4859-a42d-919feaf89d60", 
            "redirect_url": null, 
            "redirect_listener_id": "3ee10199-a7b4-4784-93cd-857afe9d0890", 
            "action": "REDIRECT_TO_LISTENER", 
            "position": 100, 
            "provisioning_status": "ACTIVE", 
            "project_id": "573d73c9f90e48d0bddfa0eb202b25c2", 
            "id": "bc4e4338-480f-4a98-8245-5bb1964f0e1d", 
            "name": "redirect-test"
        }
    }

Response Codes

For details, see HTTP Status Codes for Enhanced Load Balancers.