CreateRule
Creates a forwarding rule for a listener.
Operation description
When calling this operation to create a forwarding rule, note the following:
-
When you configure the Redirect action, you must set at least one parameter other than HttpCode to a non-default value.
-
If you specify a Rewrite action together with other actions in a forwarding rule, you must also specify a ForwardGroup action.
-
The CreateRule operation is asynchronous. After you send a request, the system returns a request ID and runs the creation task in the background. The forwarding rule is not created immediately. To query its status, call the ListRules operation:
If a forwarding rule is in the Provisioning state, the rule is being created.
If a forwarding rule is in the Available state, the rule has been created successfully.
-
A forwarding rule has the following limits for conditions (RuleConditions) and actions (RuleActions):
Conditions: 5 for a basic Application Load Balancer (ALB) instance, 10 for a standard ALB instance, and 10 for a WAF-enabled ALB instance.
Actions: 3 for a basic ALB instance, 5 for a standard ALB instance, and 5 for a WAF-enabled ALB instance.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
alb:CreateRule |
create |
*LoadBalancer
*ServerGroup
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| ListenerId |
string |
Yes |
The ID of the listener. |
lsn-l16uo9y****** |
| ClientToken |
string |
No |
The client token used to ensure request idempotence. The client must generate a unique token for each request. The token can contain only ASCII characters. Note
If you do not specify this parameter, the system uses the RequestId of the API request as the ClientToken. Each API request has a unique RequestId. |
5A2CFF0E-5718-45B5-9D4D-70B****** |
| DryRun |
boolean |
No |
Specifies whether to perform a dry run. Valid values:
|
false |
| Priority |
integer |
Yes |
The priority of the rule. Valid values: 1 to 10000. A smaller value indicates a higher priority. Note
The priority of each forwarding rule within the same listener must be unique. |
10 |
| Direction |
string |
No |
The direction in which the forwarding rule is applied. Valid values:
Note
Basic ALB instances do not support the Response type. |
Request |
| RuleActions |
array<object> |
Yes |
A list of actions for the forwarding rule. |
|
|
array<object> |
Yes |
The actions of the forwarding rule. |
||
| FixedResponseConfig |
object |
No |
The fixed response configuration. |
|
| Content |
string |
No |
The content of the fixed response. The content can be up to 1 KB in size and can contain only ASCII characters. |
dssacav |
| ContentType |
string |
No |
The content type of the fixed response. Valid values: text/plain, text/css, text/html, application/javascript, or application/json. |
text/plain |
| HttpCode |
string |
No |
The HTTP response status code. Valid values are strings that represent 2xx, 4xx, and 5xx status codes, where x is any digit. |
200 |
| ForwardGroupConfig |
object |
No |
The configuration for forwarding requests to one or more server groups. |
|
| ServerGroupTuples |
array<object> |
No |
The server groups to which requests are forwarded. You can specify up to five server groups. |
|
|
object |
No |
The configuration for a server group. |
||
| ServerGroupId |
string |
No |
The ID of the server group. |
sgp-k86c1ov501id6p**** |
| Weight |
integer |
No |
The weight of the server group. A server group with a higher weight receives more requests. Valid values: 0 to 100.
|
100 |
| ServerGroupStickySession |
object |
No |
The session persistence configuration. |
|
| Enabled |
boolean |
No |
Specifies whether to enable session persistence. Valid values:
|
false |
| Timeout |
integer |
No |
The timeout period, in seconds. Valid values: 1 to 86400. Default: 1000. |
100 |
| InsertHeaderConfig |
object |
No |
The header insertion configuration. |
|
| Key |
string |
No |
The name of the header to be inserted. The name must be 1 to 40 characters in length and can contain letters, digits, underscores (_), and hyphens (-). Header names must be unique within this action. Note
The following header names are not allowed (case-insensitive): |
key |
| Value |
string |
No |
The value of the header to be inserted.
|
UserDefined |
| ValueType |
string |
No |
The type of the header value. Valid values:
|
UserDefined |
| Order |
integer |
Yes |
The execution order of the action. Valid values: 1 to 50000. Actions are executed in ascending order of this value. Each action must have a unique order value. |
1 |
| RedirectConfig |
object |
No |
The redirect configuration. Note
You must specify a non-default value for at least one of the following parameters: Host, Path, Port, Protocol, or Query. |
|
| Host |
string |
No |
The host to which requests are redirected. Valid values:
|
${host} |
| HttpCode |
string |
No |
The redirect type. Valid values: 301, 302, 303, 307, or 308. |
301 |
| Path |
string |
No |
The path to which requests are redirected. Valid values:
|
/test |
| Port |
string |
No |
The port to which requests are redirected.
|
10 |
| Protocol |
string |
No |
The protocol to which requests are redirected. Valid values:
Note
|
HTTP |
| Query |
string |
No |
The query string to which requests are redirected.
|
${query} |
| RewriteConfig |
object |
No |
The rewrite configuration. Note
If a forwarding rule contains a Rewrite action, it must also contain a ForwardGroup action. |
|
| Host |
string |
No |
The destination host for the internal redirect. Valid values:
|
www.example.com |
| Path |
string |
No |
The path for the internal redirect. Valid values:
|
/tsdf |
| Query |
string |
No |
The query string for the internal redirect.
|
${query} |
| Type |
string |
Yes |
The type of the action. Valid values:
Note
A forwarding rule must contain one of the following actions: ForwardGroup, Redirect, or FixedResponse. This terminating action must be the last one executed in the rule. |
ForwardGroup |
| TrafficLimitConfig |
object |
No |
The traffic throttling configuration. |
|
| QPS |
integer |
No |
The number of queries per second (QPS). Valid values: 1 to 1000000. |
100 |
| PerIpQps |
integer |
No |
The number of QPS for each source IP address. Valid values: 1 to 1000000. Note
If you also configure QPS, the value of PerIpQps must be smaller than the value of QPS. |
80 |
| TrafficMirrorConfig |
object |
No |
The traffic mirroring configuration. |
|
| TargetType |
string |
No |
The type of the destination to which traffic is mirrored. Valid values:
|
ForwardGroupMirror |
| MirrorGroupConfig |
object |
No |
The server groups to which traffic is mirrored. |
|
| ServerGroupTuples |
array<object> |
No |
The server groups to which traffic is mirrored. |
|
|
object |
No |
The server groups to which traffic is mirrored. |
||
| ServerGroupId |
string |
No |
The ID of the server group. |
sgp-00mkgijak0w4qgz9**** |
| RemoveHeaderConfig |
object |
No |
The header removal configuration. |
|
| Key |
string |
No |
The name of the header to be removed. The name must be 1 to 40 characters in length and can contain letters, digits, underscores (_), and hyphens (-). Header names cannot be duplicated in
|
test |
| CorsConfig |
object |
No |
The cross-origin resource sharing (CORS) configuration. |
|
| AllowOrigin |
array |
No |
The list of allowed origins. You can specify a single value of
|
|
|
string |
No |
The allowed origin. |
http://example.com |
|
| AllowMethods |
array |
No |
The allowed HTTP methods for CORS requests. |
|
|
string |
No |
The allowed HTTP method for CORS requests. Valid values:
|
GET |
|
| AllowHeaders |
array |
No |
The list of allowed headers for CORS. |
|
|
string |
No |
The allowed header. You can specify a single value of |
test_123 |
|
| ExposeHeaders |
array |
No |
The list of allowed exposed headers. |
|
|
string |
No |
The allowed exposed header. You can specify a single value of |
test_123 |
|
| AllowCredentials |
string |
No |
Specifies whether to allow requests to carry credentials. Valid values:
|
on |
| MaxAge |
integer |
No |
The maximum time, in seconds, that a preflight request can be cached by the browser. Valid values: -1 to 172800. |
1000 |
| RuleConditions |
array<object> |
Yes |
A list of conditions for the forwarding rule. |
|
|
array<object> |
Yes |
A condition for the forwarding rule. |
||
| CookieConfig |
object |
No |
The cookie configuration. |
|
| Values |
array<object> |
No |
A list of cookie values. |
|
|
object |
No |
A cookie key-value pair. |
||
| Key |
string |
No |
The key of the cookie.
|
test |
| Value |
string |
No |
The value of the cookie.
|
test |
| HeaderConfig |
object |
No |
The header configuration. |
|
| Key |
string |
No |
The key of the header.
|
Port |
| Values |
array |
No |
A list of header values. |
|
|
string |
No |
An HTTP header value. Header values for the same key must be unique within the condition.
|
5006 |
|
| HostConfig |
object |
No |
The host configuration. |
|
| Values |
array |
No |
A list of hostnames. |
|
|
string |
No |
The hostname.
|
www.example.edu |
|
| MethodConfig |
object |
No |
The request method configuration. |
|
| Values |
array |
No |
A list of request methods. |
|
|
string |
No |
A request method. Valid values: HEAD, GET, POST, OPTIONS, PUT, PATCH, and DELETE. |
PUT |
|
| PathConfig |
object |
No |
The path configuration. |
|
| Values |
array |
No |
A list of paths. |
|
|
string |
No |
A path.
|
/test |
|
| QueryStringConfig |
object |
No |
The query string configuration. |
|
| Values |
array<object> |
No |
A list of query strings. |
|
|
object |
No |
A query string. |
||
| Key |
string |
No |
The key of the query string.
|
test |
| Value |
string |
No |
The value of the query string.
|
test |
| ResponseStatusCodeConfig |
object |
No |
The response status code configuration. |
|
| Values |
array |
No |
A list of response status codes. |
|
|
string |
No |
A response status code. |
test |
|
| ResponseHeaderConfig |
object |
No |
The header condition configuration. |
|
| Key |
string |
No |
The key of the header.
|
test |
| Values |
array |
No |
A list of header values. |
|
|
string |
No |
A header value.
|
50006 |
|
| Type |
string |
Yes |
The forwarding rule type. Valid values:
|
Host |
| SourceIpConfig |
object |
No |
The configuration for matching service traffic based on the source IP. This is required and takes effect when Type is set to SourceIP. |
|
| Values |
array |
No |
A service traffic matching list based on the source IP. |
|
|
string |
No |
Add one or more IP addresses or IP address ranges. |
192.168.0.0/32 |
|
| RuleName |
string |
Yes |
The name of the forwarding rule.
|
rule-doc |
| Tag |
array<object> |
No |
Tag list. |
|
|
object |
No |
Tag structure. |
||
| Key |
string |
No |
The tag key can be up to 128 characters in length and cannot start with aliyun or acs: or contain http:// or https://. |
env |
| Value |
string |
No |
The value cannot exceed 128 characters, start with aliyun or acs:, or contain http:// or https://. |
product |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The response body. |
||
| JobId |
string |
The ID of the asynchronous task. |
72dcd26b-f12d-4c27-b3af-18f6aed5**** |
| RequestId |
string |
The request ID. |
365F4154-92F6-4AE4-92F8-7FF34B540750 |
| RuleId |
string |
The ID of the forwarding rule. |
rule-a3x3pg1yohq3lq**** |
Examples
Success response
JSON format
{
"JobId": "72dcd26b-f12d-4c27-b3af-18f6aed5****",
"RequestId": "365F4154-92F6-4AE4-92F8-7FF34B540750",
"RuleId": "rule-a3x3pg1yohq3lq****"
}
Error codes
|
HTTP status code |
Error code |
Error message |
Description |
|---|---|---|---|
| 400 | IncorrectStatus.Listener | The status of %s [%s] is incorrect. | |
| 400 | OperationDenied.SameGroupForForwardAndMirrorAction | The operation is not allowed because of %s. | The operation is not allowed because of %s. |
| 400 | OperationDenied.IpGroupCanNotUsedForMirrorAction | The operation is not allowed because of %s. | The operation is not allowed because of %s. |
| 400 | OperationDenied.GRPCServerGroup | The operation is not allowed because of %s. | |
| 400 | Conflict.Priority | There is already %s having the same configuration with %s. | |
| 400 | ResourceQuotaExceeded.LoadBalancerRulesNum | The quota of %s is exceeded for resource %s, usage %s/%s. | |
| 400 | ResourceQuotaExceeded.ServerGroupAttachedNum | The quota of %s is exceeded for resource %s, usage %s/%s. | |
| 400 | ResourceQuotaExceeded.LoadBalancerServersNum | The quota of %s is exceeded for resource %s, usage %s/%s. | |
| 400 | ResourceQuotaExceeded.ServerAddedNum | The quota of %s is exceeded for resource %s, usage %s/%s. | |
| 400 | QuotaExceeded.RuleWildcardsNum | The quota of %s is exceeded, usage %s/%s. | The quota of %s is exceeded, usage %s/%s. |
| 400 | QuotaExceeded.RuleMatchEvaluationsNum | The quota of %s is exceeded, usage %s/%s. | |
| 400 | QuotaExceeded.RuleActionsNum | The quota of %s is exceeded, usage %s/%s. | The quota of %s is exceeded. Usage: %s/%s. |
| 400 | Mismatch.Protocol | The %s is mismatched for %s and %s. | The %s is mismatched for %s and %s. |
| 400 | Mismatch.VpcId | The %s is mismatched for %s and %s. | The %s is mismatched for %s and %s. |
| 400 | OperationDenied.RewriteMissingForwardGroup | The operation is not allowed because of RewriteMissingForwardGroup. | The operation is not allowed because rewrite is missing the forward group. |
| 400 | ResourceInConfiguring.Listener | The specified listener is being configured, please try again later. | |
| 400 | OperationDenied.MirrorActionSupportHttpGroupOnly | The operation is not allowed because of MirrorActionSupportHttpGroupOnly. | |
| 400 | OperationDenied.ProtocolMustSameForForwardGroupAction | The operation is not allowed because of ProtocolMustSameForForwardGroupAction. | |
| 404 | ResourceNotFound.Listener | The specified resource %s is not found. | |
| 404 | ResourceNotFound.ServerGroup | The specified resource %s is not found. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.