Updated on 2025-09-22 GMT+08:00

Modifying a Forwarding Policy

Function

This API is used to update a forwarding policy.

Calling Method

For details, see Calling APIs.

URI

PUT /v3/{project_id}/elb/l7policies/{l7policy_id}

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

l7policy_id

Yes

String

Definition: Specifies the forwarding policy ID.

Constraints: N/A

Range: N/A

Default value: N/A

project_id

Yes

String

Definition: Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Constraints: N/A

Range: The value can contain a maximum of 32 characters, including digits and lowercase letters.

Default value: N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition: Specifies the token used for IAM authentication.

Constraints: N/A

Range: N/A

Default value: N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

l7policy

Yes

UpdateL7PolicyOption object

Definition: Specifies the forwarding policy.

Constraints: N/A

Table 4 UpdateL7PolicyOption

Parameter

Mandatory

Type

Description

admin_state_up

No

Boolean

Definition: Specifies the administrative status of the forwarding policy.

Constraints: The value can only be true.

Range: N/A

Default value: N/A

description

No

String

Definition: Provides supplementary information about the forwarding policy.

Constraints: N/A

Range: N/A

Default value: N/A

name

No

String

Definition: Specifies the forwarding policy name.

Constraints: N/A

Range: N/A

Default value: N/A

redirect_listener_id

No

String

Definition: Specifies the ID of the listener to which requests are redirected.

Constraints:

  • If action is set to REDIRECT_TO_LISTENER, this parameter cannot be updated to an empty value or be null.

  • The listener's protocol must be HTTPS or TERMINATED_HTTPS.

  • A listener added to another load balancer is not allowed.

  • This parameter cannot be passed in the API for adding or updating a forwarding policy if action is set to REDIRECT_TO_POOL.

Range: N/A

Default value: N/A

redirect_pool_id

No

String

Definition: Specifies the ID of the backend server group to which requests will be forwarded.

Constraints:

  • The specified backend server group cannot be the default backend server group associated with the listener, or any backend server group associated with the forwarding policies of other listeners.

  • This parameter is valid when action is set to REDIRECT_TO_POOL. This parameter cannot be updated to an empty value and cannot be null.

  • If this parameter is specified when action is set to REDIRECT_TO_LISTENER, an error will be reported.

Range: N/A

Default value: N/A

redirect_pools_config

No

Array of UpdateRedirectPoolsConfig objects

Definition: Specifies the new weights of backend server group that the requests are forwarded to. This parameter takes effect only when enhance_l7policy_enable is set to true. If this parameter is specified and enhance_l7policy_enable is set to false, an error will be returned.

Constraints:

  • If action is set to REDIRECT_TO_POOL, specify either redirect_pool_id or redirect_pools_config. If both are specified, only redirect_pools_config takes effect.

  • If action is set to REDIRECT_TO_LISTENER or REDIRECT_TO_URL and this parameter is specified, an error will be returned.

  • A maximum of five backend server groups can be configured for a forwarding policy. Each backend server group must be unique.

  • All backend server groups will be overwritten, and the backend server groups that are not included in the request parameter in the request body will be removed.

This parameter is unsupported for shared load balancers. If it is passed, an error will be returned.

redirect_pools_sticky_session_config

No

UpdateRedirectPoolsStickySessionConfig object

Definition: Specifies whether to enable sticky session for backend server groups configured for a forwarding policy. The load balancer generates a cookie after it receives a request from a client. All subsequent requests with the same cookie are routed to the same backend server group.

Constraints: This parameter is unsupported for shared load balancers. If it is passed, an error will be returned.

redirect_url_config

No

UpdateRedirectUrlConfig object

Definition: Specifies the URL to which requests are forwarded.

Constraints:

  • This parameter takes effect only when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned.

  • This parameter is mandatory when action is set to REDIRECT_TO_URL. It cannot be specified if the value of action is not REDIRECT_TO_URL. Otherwise, an error is reported.

  • For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned.

fixed_response_config

No

UpdateFixtedResponseConfig object

Definition: Specifies the configuration of the page that will be returned.

Constraints:

  • This parameter takes effect only when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned.

  • This parameter is mandatory when action is set to FIXED_RESPONSE. It cannot be specified if action is set to other values.

  • For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned.

redirect_pools_extend_config

No

UpdateRedirectPoolsExtendConfig object

Definition: Specifies the backend server group that requests are forwarded to.

Constraints: This parameter takes effect only when action is set to REDIRECT_TO_POOL.

rules

No

Array of CreateRuleOption objects

Definition: Lists the forwarding rules in the forwarding policy.

Constraints:

  • Each list can contain a maximum of 10 forwarding rules (if conditions is specified, a condition is considered as a rule). If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type.

  • The entire list will be replaced if you update it.

priority

No

Integer

Definition: Specifies the priority of the forwarding policy. A smaller value indicates a higher priority.

Constraints:

  • The priority must be unique for forwarding policies of the same listener.

  • This parameter takes effect only when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned.

  • If enhance_l7policy_enable is set to false, forwarding policies are automatically prioritized based on the original policy sorting logic. The priorities of domain names are independent from each other. For the same domain name, the priorities are sorted in the order of exact match (EQUAL_TO), prefix match (STARTS_WITH), and regular expression match (REGEX). If the matching types are the same, the longer the path is, the higher the priority is. If a forwarding policy contains only a domain name without a path specified, the path is /, and prefix match is used by default.

  • This parameter is unsupported for shared load balancers.

Range:

  • If action is set to REDIRECT_TO_LISTENER, the priority ranges from 0 to 10,000.

  • If action is set to other values, the priority ranges from 1 to 10,000.

Default value:

  • If this parameter is not passed and enhance_l7policy_enable is set to false, the priority of the new forwarding policy is 1.

  • If action is set to REDIRECT_TO_LISTENER, the priority of the new forwarding policy is 0.

  • If action is set to other values, the priority of the new forwarding policy will be a sum of 1 and the highest priority of existing forwarding policy in the same listener by default.

    • If there is no forwarding policy, the priority of a new forwarding policy will be 1 by default.

    • If the priority of an existing forwarding policy is the maximum value (10,000), the forwarding policy will fail to be created because the maximum value will be exceeded. In this case, specify a value or adjust the priorities of existing forwarding policies.

Table 5 UpdateRedirectPoolsConfig

Parameter

Mandatory

Type

Description

pool_id

Yes

String

Definition: Specifies the backend server group ID.

Constraints: N/A

Range: N/A

Default value: N/A

weight

No

String

Definition: Specifies the weight of the backend server group. Requests are routed to backend server groups based on their weights. The larger the weight is, the higher proportion of requests the backend server group receives. If the weight is set to 0, the backend server group will not accept new requests.

Constraints: N/A

Range: 0 to 100

Default value: N/A

Table 6 UpdateRedirectPoolsStickySessionConfig

Parameter

Mandatory

Type

Description

enable

No

Boolean

Definition: Specifies whether to enable sticky session for backend server groups configured in a forwarding policy.

Constraints: N/A

Range: N/A

Default value: false, indicating that sticky session is disabled.

timeout

No

Integer

Definition: Specifies the stickiness duration, in minutes.

Constraints: N/A

Range: 1 to 1440

Default value: 1440

Table 7 UpdateRedirectUrlConfig

Parameter

Mandatory

Type

Description

protocol

No

String

Definition: Specifies the protocol for redirection.

Constraints: N/A

Range:

  • HTTP

  • HTTPS

  • ${protocol}: indicates that the protocol in the request will be used.

Default value: N/A

host

No

String

Definition: Specifies the name of the host that requests are redirected to.

Constraints: N/A

Range: The value can contain only letters, digits, hyphens (-), and periods (.) and must start with a letter or digit.

Default value: ${host}, indicating that the host in the request will be used.

port

No

String

Definition: Specifies the port that requests are redirected to.

Constraints: N/A

Range: N/A

Default value: ${port}, indicating that the port in the request will be used.

path

No

String

Definition: Specifies the path that requests are redirected to.

Constraints: N/A

Range: The value can contain only letters, digits, and special characters: _~';@^-%#&$.*+?,=!:|\/()[]{} and must start with a slash (/).

Default value: ${path}, indicating that the path in the request will be used.

query

No

String

Definition: Specifies the query string set in the URL for redirection. The following is an example:

In the URL https://www.example.com:8080/elb?type=loadbalancer, if this parameter is set to ${query}&name=my_name, the URL will be redirected to https://www.example.com:8080/elb?type=loadbalancer&name=my_name. In the example, ${query} indicates type=loadbalancer.

Constraints: N/A

Range: The value can contain only letters, digits, and the special characters: !$&'()*+,-./:;=?@^_`. The letters are case-sensitive. $1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the requested URL.

Default value: ${query}, indicating that the query string in the request will be used.

status_code

No

String

Definition: Specifies the status code returned after the requests are redirected.

Constraints: N/A

Range:

  • 301

  • 302

  • 303

  • 307

  • 308

Default value: N/A

insert_headers_config

No

UpdateInsertHeadersConfig object

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

Constraints: N/A

remove_headers_config

No

UpdateRemoveHeadersConfig object

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

Default value: N/A

Table 8 UpdateFixtedResponseConfig

Parameter

Mandatory

Type

Description

status_code

No

String

Definition: Specifies the HTTP status code.

Constraints: N/A

Range: 200-299, 400-499, 500-599

Default value: N/A

content_type

No

String

Definition: Specifies the format of the returned body.

Constraints: N/A

Range:

  • text/plain

  • text/css

  • text/html

  • application/javascript

  • application/json

Default value: application/json

message_body

No

String

Definition: Specifies the content of the response message body.

Constraints: N/A

Range: N/A

Default value: N/A

insert_headers_config

No

UpdateInsertHeadersConfig object

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

Constraints: N/A

remove_headers_config

No

UpdateRemoveHeadersConfig object

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

Default value: N/A

traffic_limit_config

No

UpdateTrafficLimitConfig object

Definition: Specifies how requests are limited.

Constraints: N/A

Table 9 UpdateRedirectPoolsExtendConfig

Parameter

Mandatory

Type

Description

rewrite_url_enable

No

Boolean

Definition: Specifies whether to set rewrite_url_enable to true.

Constraints: N/A

Range: The value can be true (enable this option) or false (disable this option).

Default value: N/A

rewrite_url_config

No

UpdateRewriteUrlConfig object

Definition: Specifies the URL for the backend server group that requests are forwarded to.

Constraints: This parameter takes effect only when action is set to REDIRECT_TO_POOL.

insert_headers_config

No

UpdateInsertHeadersConfig object

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

Constraints: N/A

remove_headers_config

No

UpdateRemoveHeadersConfig object

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

Default value: N/A

traffic_limit_config

No

UpdateTrafficLimitConfig object

Definition: Specifies how requests are limited.

Constraints: N/A

cors_config

No

CreateCorsConfig object

Definition: Specifies the CORS configurations.

Constraints: N/A

traffic_mirror_config

No

CreateTrafficMirrorConfig object

Definition: Specifies the traffic mirroring configuration.

Constraints: N/A

Table 10 UpdateRewriteUrlConfig

Parameter

Mandatory

Type

Description

host

No

String

Definition: Specifies the domain name of the host that requests are redirected to.

Constraints: N/A

Range: The value can contain letters, digits, hyphens (-), and periods (.), and must start with a letter or digit.

Default value: N/A

path

No

String

Definition: Specifies the path that requests are redirected to. $1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the request URL. If the number of regular expression match groups is less than the specified number, ${path} is empty. If the dollar sign ($) is followed by a letter, the matching result is empty until the next special character appears, for example, $abc#123, and the matching result is #123. If the dollar sign ($) is followed by a special character, for example, $#, the matching result is $#.

Constraints: N/A

Range: The value must start with a slash (/) and can contain only letters, digits, and special characters: _~';@^-%#&$.+?,=!:|/()

Default value: N/A

query

No

String

Definition: Specifies the query string set in the URL for redirection. $1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the request URL. If the number of regular expression match groups is less than the specified number, ${path} is empty. If the dollar sign ($) is followed by a letter, the matching result is empty until the next special character appears, for example, $abc#123, and the matching result is #123. If the dollar sign ($) is followed by a special character, for example, $#, the matching result is $#.

Constraints: N/A

Range: The value can contain only letters, digits, and the special characters: !$&'()+,-./:;=?@^_`. The letters are case-sensitive.

Default value: N/A

Table 11 UpdateInsertHeadersConfig

Parameter

Mandatory

Type

Description

configs

Yes

Array of UpdateInsertHeaderConfig objects

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

Constraints: N/A

Table 12 UpdateInsertHeaderConfig

Parameter

Mandatory

Type

Description

key

Yes

String

Definition: Specifies the key of the header you want to write into the request that matches the forwarding rule.

Constraints: The following cannot be used as a key.

connection, upgrade, content-length, transfer-encoding, keep-alive, te, host, cookie, remoteip, authority, x-forwarded-host, x-forwarded-for, x-forwarded-for-port, x-forwarded-tls-certificate-id, x-forwarded-tls-protocol, x-forwarded-tls-cipher, x-forwarded-elb-ip, x-forwarded-port, x-forwarded-elb-id, x-forwarded-elb-vip, x-real-ip, x-forwarded-proto, x-nuwa-trace-ne-in, or x-nuwa-trace-ne-out

Range: The value can contain 1 to 40 characters, including letters (case-insensitive), digits, hyphens (-), and underscores (_).

Default value: N/A

value_type

Yes

String

Definition: Specifies the value type of the header.

Constraints: N/A

Range: USER_DEFINED, REFERENCE_HEADER, or SYSTEM_DEFINED

Default value: N/A

value

Yes

String

Definition: Specifies the value of the header.

Constraints: If value_type is set to SYSTEM_DEFINED, the value can be CLIENT-PORT, CLIENT-IP, ELB-PROTOCOL, ELB-ID, ELB-PORT, ELB-EIP, or ELB-VIP.

Range: The value can contain 1 to 128 characters. ASCII codes 32 through 127 printable characters, asterisk (*), and question mark (?) are also supported. The value cannot start or end with a space.

Default value: N/A

Table 13 UpdateRemoveHeadersConfig

Parameter

Mandatory

Type

Description

configs

Yes

Array of UpdateRemoveHeaderConfig objects

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

Default value: N/A

Table 14 UpdateRemoveHeaderConfig

Parameter

Mandatory

Type

Description

key

Yes

String

Definition: Specifies the key of the header you want to remove from the request that matches the forwarding rule.

Constraints: The following cannot be used as a key.

connection, upgrade, content-length, transfer-encoding, keep-alive, te, host, cookie, remoteip, authority, x-forwarded-host, x-forwarded-for, x-forwarded-for-port, x-forwarded-tls-certificate-id, x-forwarded-tls-protocol, x-forwarded-tls-cipher, x-forwarded-elb-ip, x-forwarded-port, x-forwarded-elb-id, x-forwarded-elb-vip, x-real-ip, x-forwarded-proto, x-nuwa-trace-ne-in, or x-nuwa-trace-ne-out

Range: The value can contain 1 to 40 characters, including letters (case-insensitive), digits, hyphens (-), and underscores (_).

Default value: N/A

Table 15 UpdateTrafficLimitConfig

Parameter

Mandatory

Type

Description

qps

No

Integer

Definition: Specifies the maximum number of queries per second (QPS).

Constraints: N/A

Range: 0 to 100000. Unit: count/s. 0 indicates that QPS is not limited.

Default value: N/A

per_source_ip_qps

No

Integer

Definition: Specifies the maximum number of queries per second (QPS) from a source IP address (single client).

Constraints:

  • This parameter is not available for QUIC listeners.

  • The value can be 0 or null.

  • If qps is not set to 0, per_source_ip_qps must be specified a smaller value than qps.

Range: 0 to 100000. Unit: count/s. 0 indicates that QPS is not limited.

Default value: N/A

burst

No

Integer

Definition: Specifies the allowed burst queries if the number of queries exceeds the value specified for qps. If the number of burst queries exceeds the value specified for burst, 503 Service Unavailable will be returned to the client.

Constraints: N/A

Range: 0 to 100000. Unit: count/s.

Default value: N/A

Table 16 CreateCorsConfig

Parameter

Mandatory

Type

Description

allow_origin

No

Array of strings

Definition: Specifies the origins that are allowed to access cross-origin resources through a browser. The origin can be a wildcard (*) or one or more URLs.

Constraints:

  • Each URL must start with http:// or https://, followed by a valid domain name or level-1 wildcard domain name, for example, http://*.test.abc.example.com.

  • It is optional to include a port number (ranging from 1 to 65535) in the URL.

Range: N/A

Default value: N/A

allow_methods

No

Array of strings

Definition: Specifies the HTTP methods that the specified URLs can use to access cross-origin resources.

Constraints: N/A

Range: N/A

Default value: N/A

allow_headers

No

Array of strings

Definition: Specifies the request headers that can be carried in CORS requests.

Constraints: N/A

Range: N/A

Default value: N/A

expose_headers

No

Array of strings

Definition: Specifies the headers that can be exposed.

Constraints: N/A

Range: N/A

Default value: N/A

allow_credentials

No

Boolean

Definition: Specifies whether to allow credentials in CORS requests.

Constraints: N/A

Range:

  • true: Credentials are allowed.

  • false: Credentials are not allowed.

Default value: N/A

max_age

No

Long

Definition: Specifies the maximum duration a preflight request can be cached, in seconds.

Constraints: N/A

Range: -1 to 172800

Default value: N/A

Table 17 CreateTrafficMirrorConfig

Parameter

Mandatory

Type

Description

target_ids

No

Array of strings

Definition: Specifies the IDs of the backend server groups that traffic is mirrored to.

Constraints: N/A

Range: N/A

Default value: N/A

mirror_request_body_enable

No

Boolean

Specifies whether to include the mirror request body. The default value is true.

Constraints: N/A

Range: N/A

Default value: N/A

Table 18 CreateRuleOption

Parameter

Mandatory

Type

Description

admin_state_up

No

Boolean

Definition: Specifies the administrative status of the forwarding rule.

Constraints: The value can only be true.

Range: N/A

Default value: N/A

compare_type

Yes

String

Definition: Specifies how requests are matched with the forwarding rule.

Constraints:

  • If type is set to HOST_NAME, the value can only be EQUAL_TO, and asterisks (*) can be used as wildcard characters.

  • If type is set to PATH, the value can be REGEX, STARTS_WITH, or EQUAL_TO.

  • If type is set to METHOD or SOURCE_IP, the value can only be EQUAL_TO.

  • If type is set to HEADER or QUERY_STRING, the value can only be EQUAL_TO, asterisks (*) and question marks (?) can be used as wildcard characters.

Range:

  • EQUAL_TO: exact match

  • REGEX: regular expression match

  • STARTS_WITH: prefix match

Default value: N/A

key

No

String

Definition: Specifies the key of the match item. For example, if an HTTP header is used for matching, key is the name of the HTTP header parameter.

Constraints: N/A

Range: N/A

Default value: N/A

This parameter is unsupported. Please do not use it.

value

Yes

String

Definition: Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name.

Constraints: This parameter takes effect only when conditions is left blank.

Range:

  • If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), periods (.), and asterisks (*), and must start with a letter, digit, or asterisk (*). If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name.

  • If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) and can contain only letters, digits, and special characters: _~';@^-%#&$.*+?,=!:|\/()[]{}

  • If type is set to METHOD, SOURCE_IP, HEADER, or QUERY_STRING, this parameter will not take effect, and conditions will be used to specify the key and value.

Default value: N/A

project_id

No

String

Definition: Specifies the ID of the project where the forwarding rule is used.

Constraints: N/A

Range: N/A

Default value: N/A

type

Yes

String

Definition: Specifies the forwarding rule type.

Constraints:

If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. If type is set to HEADER and QUERY_STRING, multiple forwarding rules can be created for each type.

Range:

  • HOST_NAME: A domain name will be used for matching.

  • PATH: A URL will be used for matching.

  • METHOD: A request method will be used for matching.

  • HEADER: A request header will be used for matching.

  • QUERY_STRING: A query string will be used for matching.

  • SOURCE_IP: A source IP address will be used for matching.

  • COOKIE: A cookie will be used for matching.

Default value: N/A

invert

No

Boolean

Definition: Specifies whether reverse matching is supported.

Constraints: N/A

Range: true or false

Default value: false

This parameter is unsupported. Please do not use it.

conditions

No

Array of CreateRuleCondition objects

Definition: Specifies the conditions contained in a forwarding rule.

Constraints:

  • This parameter takes effect only when enhance_l7policy_enable is set to true.

  • If conditions is set for a forwarding rule, the values of key and value are ignored.

  • All keys in the conditions of a rule must be the same, and the values must be unique.

Range: N/A

Default value: N/A

Table 19 CreateRuleCondition

Parameter

Mandatory

Type

Description

key

No

String

Definition: Specifies the key of match item.

Constraints: All keys in the conditions list in the same rule must be the same.

Range:

  • If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, this parameter is an empty string.

  • If type is set to HEADER, key indicates the name of the HTTP header parameter, and value indicates the value of the request header parameter. Each key can contain 1 to 40 characters, including letters, digits, hyphens (-), and underscores (_).

  • If type is set to QUERY_STRING, key indicates the name of the query parameter, and value indicates the value of the query parameter. The key is case sensitive and can contain 1 to 128 characters. Spaces, square brackets ([ ]), curly brackets ({ }), angle brackets (< >), backslashes (), double quotation marks (" "), pound signs (#), ampersands (&), vertical bars (|), percent signs (%), and tildes (~) are not allowed.

Default value: N/A

value

Yes

String

Definition: Specifies the value of the match item.

Constraints:

  • The key of each condition in a forwarding rule must be the same.

  • The value of each condition in a forwarding rule must be unique.

Range:

  • If type is set to HOST_NAME, key is always an empty string and value indicates the domain name. Each value can contain 1 to 128 characters, including letters, digits, hyphens (-), periods (.), and asterisks (*), and must start with a letter, digit, or asterisk (*). If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name.

  • If type is set to PATH, key is always an empty string and value indicates the request path, which can contain 1 to 128 characters. If compare_type is set to STARTS_WITH or EQUAL_TO for a forwarding rule, the value must start with a slash (/) and can contain only letters, digits, and special characters: _~';@^-%#&$.*+?,=!:|\/()[]{}

  • If type is set to HEADER, key indicates the name of the HTTP header parameter, and value indicates the value of the request header parameter. The value can contain 1 to 128 characters. Asterisks (*) and question marks (?) are allowed, but spaces and double quotation marks are not allowed. An asterisk can match zero or more characters, and a question mark can match one character.

  • If type is set to QUERY_STRING, key indicates the name of the query parameter, and value indicates the value of the query parameter. The value is case sensitive and can contain 1 to 128 characters. Spaces, square brackets ([ ]), curly brackets ({ }), angle brackets (< >), backslashes (), double quotation marks (" "), pound signs (#), ampersands (&), vertical bars (|), percent signs (%), and tildes (~) are not allowed. Asterisks (*) and question marks (?) are allowed. An asterisk can match zero or more characters, and a question mark can match one character.

  • If type is set to METHOD, key is always an empty string and value indicates the HTTP method. The value can be GET, PUT, POST, DELETE, PATCH, HEAD, or OPTIONS.

  • If type is set to SOURCE_IP, key is always an empty string and value indicates the source IP address of the request. The value is an IPv4 or IPv6 CIDR block, for example, 192.168.0.2/32 or 2049::49/64.

Default value: N/A

Response Parameters

Status code: 200

Table 20 Response body parameters

Parameter

Type

Description

request_id

String

Definition: Specifies the request ID.

Range: The value is automatically generated, and can contain characters including digits, lowercase letters, and hyphens (-).

l7policy

L7Policy object

Definition: Specifies the forwarding policy.

Table 21 L7Policy

Parameter

Type

Description

action

String

Definition: Specifies the action of the forwarding policy.

Range:

  • REDIRECT_TO_POOL: Requests are forwarded to another backend server group.

  • REDIRECT_TO_LISTENER: Requests are redirected to an HTTPS listener.

  • REDIRECT_TO_URL: Requests are redirected to another URL.

  • FIXED_RESPONSE: A fixed response body is returned.

admin_state_up

Boolean

Definition: Specifies the administrative status of the forwarding policy.

Range: The value can only be true.

description

String

Definition: Provides supplementary information about the forwarding policy.

Range: N/A

id

String

Definition: Specifies the forwarding policy ID.

Range: N/A

listener_id

String

Definition: Specifies the ID of the listener with which the forwarding policy is associated.

Range: N/A

name

String

Definition: Specifies the forwarding policy name.

Range: N/A

position

Integer

Definition: Specifies the priority of the forwarding policy. The priority cannot be updated.

This parameter is unsupported. Please do not use it.

priority

Integer

Definition: Specifies the priority of the forwarding policy. A smaller value indicates a higher priority.

Range:

  • If action is set to REDIRECT_TO_LISTENER, the priority ranges from 0 to 10,000.

  • If action is set to other values, the priority ranges from 1 to 10,000.

project_id

String

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

Range: N/A

provisioning_status

String

Definition: Specifies the provisioning status of the forwarding policy.

Range:

  • ACTIVE (default): The forwarding policy is provisioned successfully.

  • ERROR: The forwarding policy has the same rule as another forwarding policy added to the same listener.

redirect_pool_id

String

Definition: Specifies the ID of the backend server group to which requests will be forwarded.

Range: N/A

redirect_listener_id

String

Definition: Specifies the ID of the listener to which requests are redirected.

Range: N/A

redirect_url

String

Definition: Specifies the URL to which requests will be forwarded.

Range: The value must be in the format of protocol://host:port/path?query.

This parameter is unsupported. Please do not use it.

rules

Array of RuleRef objects

Definition: Lists the forwarding rules in the forwarding policy.

redirect_url_config

RedirectUrlConfig object

Definition: Specifies the URL to which requests are forwarded.

redirect_pools_config

Array of RedirectPoolsConfig objects

Definition: Specifies the backend server groups that the requests are forwarded to. This parameter takes effect only when enhance_l7policy_enable is set to true. If this parameter is specified and enhance_l7policy_enable is set to false, an error will be returned.

redirect_pools_sticky_session_config

RedirectPoolsStickySessionConfig object

Definition: Specifies whether to enable sticky session for backend server groups configured for a forwarding policy. The load balancer generates a cookie after it receives a request from a client. All subsequent requests with the same cookie are routed to the same backend server group.

redirect_pools_extend_config

RedirectPoolsExtendConfig object

Definition: Specifies the backend server group that requests are forwarded to.

fixed_response_config

FixtedResponseConfig object

Definition: Specifies the configuration of the page that will be returned.

created_at

String

Definition: Specifies the creation time.

Range: The value must be a UTC time in the yyyy-MM-dd'T'HH:mm:ss'Z' format.

Note: This parameter will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

updated_at

String

Definition: Specifies the update time.

Range: The value must be a UTC time in the yyyy-MM-dd'T'HH:mm:ss'Z' format.

Note: This parameter will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

enterprise_project_id

String

Definition: Specifies the enterprise project ID.

Range: N/A

Table 22 RuleRef

Parameter

Type

Description

id

String

Definition: Specifies the forwarding rule ID.

Range: N/A

Table 23 RedirectUrlConfig

Parameter

Type

Description

protocol

String

Definition: Specifies the protocol for redirection.

Range:

  • HTTP

  • HTTPS

  • ${protocol}: indicates that the protocol in the request will be used.

host

String

Definition: Specifies the name of the host that requests are redirected to.

Range: The value can contain only letters, digits, hyphens (-), and periods (.) and must start with a letter or digit.

port

String

Definition: Specifies the port that requests are redirected to.

Range: N/A

path

String

Definition: Specifies the path that requests are redirected to.

Range: The value can contain only letters, digits, and special characters: _~';@^-%#&$.*+?,=!:|\/()[]{} and must start with a slash (/).

query

String

Definition: Specifies the query string set in the URL for redirection. The following is an example:

In the URL https://www.example.com:8080/elb?type=loadbalancer, if this parameter is set to ${query}&name=my_name, the URL will be redirected to https://www.example.com:8080/elb?type=loadbalancer&name=my_name. In the example, ${query} indicates type=loadbalancer.

Range: The value can contain only letters, digits, and the special characters: !$&'()*+,-./:;=?@^_`. The letters are case-sensitive. $1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the requested URL.

status_code

String

Definition: Specifies the status code returned after the requests are redirected.

Range:

  • 301

  • 302

  • 303

  • 307

  • 308

insert_headers_config

InsertHeadersConfig object

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

remove_headers_config

RemoveHeadersConfig object

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

Table 24 RedirectPoolsConfig

Parameter

Type

Description

pool_id

String

Definition: Specifies the backend server group ID.

Range: N/A

weight

Integer

Definition: Specifies the weight of the backend server group. Requests are routed to backend server groups based on their weights. The larger the weight is, the higher proportion of requests the backend server group receives. If the weight is set to 0, the backend server group will not accept new requests.

Range: 0 to 100

Table 25 RedirectPoolsStickySessionConfig

Parameter

Type

Description

enable

Boolean

Definition: Specifies whether to enable sticky session for backend server groups configured in a forwarding policy.

Default value: false, indicating that sticky session is disabled.

timeout

Integer

Definition: Specifies the stickiness duration, in minutes.

Range: 1 to 1440

Table 26 RedirectPoolsExtendConfig

Parameter

Type

Description

rewrite_url_enable

Boolean

Definition: Specifies whether to set rewrite_url_enable to true.

Range: The value can be true (enable this option) or false (disable this option).

rewrite_url_config

RewriteUrlConfig object

Definition: Specifies the URL for the backend server group that requests are forwarded to.

insert_headers_config

InsertHeadersConfig object

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

remove_headers_config

RemoveHeadersConfig object

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

traffic_limit_config

TrafficLimitConfig object

Definition: Specifies how requests are limited.

cors_config

CorsConfig object

Definition: Specifies the CORS configurations.

traffic_mirror_config

TrafficMirrorConfig object

Definition: Specifies the traffic mirroring configuration.

Table 27 RewriteUrlConfig

Parameter

Type

Description

host

String

Definition: Specifies the domain name of the host that requests are redirected to.

Range: The value can contain letters, digits, hyphens (-), and periods (.), and must start with a letter or digit.

path

String

Definition: Specifies the path that requests are redirected to. $1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the request URL. If the number of regular expression match groups is less than the specified number, ${path} is empty. If the dollar sign ($) is followed by a letter, the matching result is empty until the next special character appears, for example, $abc#123, and the matching result is #123. If the dollar sign ($) is followed by a special character, for example, $#, the matching result is $#.

Range: The value must start with a slash (/) and can contain only letters, digits, and special characters: _~';@^-%#&$.+?,=!:|/()

query

String

Definition: Specifies the query string set in the URL for redirection. $1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the request URL. If the number of regular expression match groups is less than the specified number, ${path} is empty. If the dollar sign ($) is followed by a letter, the matching result is empty until the next special character appears, for example, $abc#123, and the matching result is #123. If the dollar sign ($) is followed by a special character, for example, $#, the matching result is $#.

Range: The value can contain only letters, digits, and the special characters: !$&'()+,-./:;=?@^_`. The letters are case-sensitive.

Table 28 CorsConfig

Parameter

Type

Description

allow_origin

Array of strings

Definition: Specifies the origins that are allowed to access cross-origin resources through a browser. The origin can be a wildcard (*) or one or more URLs.

Constraints:

  • Each URL must start with http:// or https://, followed by a valid domain name or level-1 wildcard domain name, for example, http://*.test.abc.example.com.

  • It is optional to include a port number (ranging from 1 to 65535) in the URL.

allow_methods

Array of strings

Definition: Specifies the HTTP methods that the specified URLs can use to access cross-origin resources.

Range: N/A

allow_headers

Array of strings

Definition: Specifies the request headers that can be carried in CORS requests.

Range: N/A

expose_headers

Array of strings

Definition: Specifies the headers that can be exposed.

Range: N/A

allow_credentials

Boolean

Definition: Specifies whether to allow credentials in CORS requests.

Range:

  • true: Credentials are allowed.

  • false: Credentials are not allowed.

max_age

Long

Definition: Specifies the maximum duration a preflight request can be cached, in seconds.

Range: -1 to 172800

Table 29 TrafficMirrorConfig

Parameter

Type

Description

target_ids

Array of strings

Definition: Specifies the IDs of the backend server groups that traffic is mirrored to.

Range: N/A

mirror_request_body_enable

Boolean

Specifies whether to include the mirror request body. The default value is true.

Range: N/A

Table 30 FixtedResponseConfig

Parameter

Type

Description

status_code

String

Definition: Specifies the HTTP status code.

Range: 200-299, 400-499, 500-599

content_type

String

Definition: Specifies the format of the returned body.

Range:

  • text/plain

  • text/css

  • text/html

  • application/javascript

  • application/json

message_body

String

Definition: Specifies the content of the response message body.

Range: N/A

insert_headers_config

InsertHeadersConfig object

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

remove_headers_config

RemoveHeadersConfig object

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

traffic_limit_config

TrafficLimitConfig object

Definition: Specifies how requests are limited.

Table 31 InsertHeadersConfig

Parameter

Type

Description

configs

Array of InsertHeaderConfig objects

Definition: Specifies the headers you want to write into the request that matches the forwarding rule.

Constraints: N/A

Table 32 InsertHeaderConfig

Parameter

Type

Description

key

String

Definition: Specifies the key of the header you want to write into the request that matches the forwarding rule.

Range: The value can contain 1 to 40 characters, including letters (case-insensitive), digits, hyphens (-), and underscores (_).

value_type

String

Definition: Specifies the value type of the header.

Range: USER_DEFINED, REFERENCE_HEADER, or SYSTEM_DEFINED

value

String

Definition: Specifies the value of the header.

Range: The value can contain 1 to 128 characters. ASCII codes 32 through 127 printable characters, asterisk (*), and question mark (?) are also supported. The value cannot start or end with a space.

Table 33 RemoveHeadersConfig

Parameter

Type

Description

configs

Array of RemoveHeaderConfig objects

Definition: Specifies the headers you want to remove from the request that matches the forwarding rule.

Constraints: N/A

Table 34 RemoveHeaderConfig

Parameter

Type

Description

key

String

Definition: Specifies the key of the header you want to remove from the request that matches the forwarding rule.

Range: The value can contain 1 to 40 characters, including letters (case-insensitive), digits, hyphens (-), and underscores (_).

Table 35 TrafficLimitConfig

Parameter

Type

Description

qps

Integer

Definition: Specifies the maximum number of queries per second (QPS).

Range: 0 to 100000. Unit: count/s. 0 indicates that QPS is not limited.

per_source_ip_qps

Integer

Definition: Specifies the maximum number of queries per second (QPS) from a source IP address (single client).

Range: 0 to 100000. Unit: count/s. 0 indicates that QPS is not limited.

burst

Integer

Definition: Specifies the allowed burst queries if the number of queries exceeds the value specified for qps. If the number of burst queries exceeds the value specified for burst, 503 Service Unavailable will be returned to the client.

Range: 0 to 100000. Unit: count/s.

Example Requests

Modifying a forwarding policy

PUT https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/l7policies/cf4360fd-8631-41ff-a6f5-b72c35da74be

{
  "l7policy" : {
    "name" : "My policy.",
    "description" : "Update policy.",
    "redirect_listener_id" : "48a97732-449e-4aab-b561-828d29e45050"
  }
}

Example Responses

Status code: 200

Successful request.

{
  "request_id" : "e5c07525-1470-47b6-9b0c-567527a036aa",
  "l7policy" : {
    "redirect_pool_id" : "768e9e8c-e7cb-4fef-b24b-af9399dbb240",
    "description" : "",
    "admin_state_up" : true,
    "rules" : [ {
      "id" : "c5c2d625-676b-431e-a4c7-c59cc2664881"
    } ],
    "project_id" : "7a9941d34fc1497d8d0797429ecfd354",
    "listener_id" : "cdb03a19-16b7-4e6b-bfec-047aeec74f56",
    "redirect_url" : null,
    "redirect_url_config" : null,
    "redirect_pools_config" : {
      "pool_id" : "722e9e8c-e7cb-4fef-b24b-af9399dbb240",
      "weight" : 12
    },
    "redirect_pools_sticky_session_config" : {
      "timeout" : 23,
      "enable" : false
    },
    "fixed_response_config" : null,
    "redirect_listener_id" : null,
    "action" : "REDIRECT_TO_POOL",
    "position" : 100,
    "priority" : null,
    "provisioning_status" : "ACTIVE",
    "id" : "01832d99-bbd8-4340-9d0c-6ff8f7a37307",
    "name" : "l7policy-67"
  }
}

SDK Sample Code

The SDK sample code is as follows.

Modifying a forwarding policy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.elb.v3.region.ElbRegion;
import com.huaweicloud.sdk.elb.v3.*;
import com.huaweicloud.sdk.elb.v3.model.*;


public class UpdateL7PolicySolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        ElbClient client = ElbClient.newBuilder()
                .withCredential(auth)
                .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateL7PolicyRequest request = new UpdateL7PolicyRequest();
        request.withL7policyId("{l7policy_id}");
        UpdateL7PolicyRequestBody body = new UpdateL7PolicyRequestBody();
        UpdateL7PolicyOption l7policybody = new UpdateL7PolicyOption();
        l7policybody.withDescription("Update policy.")
            .withName("My policy.")
            .withRedirectListenerId("48a97732-449e-4aab-b561-828d29e45050");
        body.withL7policy(l7policybody);
        request.withBody(body);
        try {
            UpdateL7PolicyResponse response = client.updateL7Policy(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Modifying a forwarding policy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkelb.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = ElbClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(ElbRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateL7PolicyRequest()
        request.l7policy_id = "{l7policy_id}"
        l7policybody = UpdateL7PolicyOption(
            description="Update policy.",
            name="My policy.",
            redirect_listener_id="48a97732-449e-4aab-b561-828d29e45050"
        )
        request.body = UpdateL7PolicyRequestBody(
            l7policy=l7policybody
        )
        response = client.update_l7_policy(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Modifying a forwarding policy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := elb.NewElbClient(
        elb.ElbClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateL7PolicyRequest{}
	request.L7policyId = "{l7policy_id}"
	descriptionL7policy:= "Update policy."
	nameL7policy:= "My policy."
	redirectListenerIdL7policy:= "48a97732-449e-4aab-b561-828d29e45050"
	l7policybody := &model.UpdateL7PolicyOption{
		Description: &descriptionL7policy,
		Name: &nameL7policy,
		RedirectListenerId: &redirectListenerIdL7policy,
	}
	request.Body = &model.UpdateL7PolicyRequestBody{
		L7policy: l7policybody,
	}
	response, err := client.UpdateL7Policy(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Successful request.

Error Codes

See Error Codes.