If you need to distribute traffic based on request attributes such as the domain name, path, HTTP headers, and cookies, you can create custom forwarding rules for a listener. The listener evaluates incoming requests against these rules and performs different forwarding actions. To create forwarding rules, call the CreateForwardingRules API.
Operation description
Before you call this API, you should understand how forwarding rules work and their matching conditions. For more information, see Forwarding rules.
When you call this API, note the following:
-
The CreateForwardingRules API is asynchronous. After the call is made, the system returns a forwarding rule ID, but the rule is still being created. You can call ListForwardingRules to query the status of the forwarding rule:
-
If a forwarding rule is in the configuring status, it is still being created, and you can only perform query operations.
-
If a forwarding rule is in the active status, the rule has been created.
-
-
You cannot use the CreateForwardingRules API to create forwarding rules concurrently for the same Global Accelerator instance.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
ga:CreateForwardingRules |
create |
*Listener
*Accelerator
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| RegionId |
string |
Yes |
The ID of the region where the Global Accelerator instance is deployed. The only valid value is cn-hangzhou. |
cn-hangzhou |
| ClientToken |
string |
No |
The client token that is used to ensure the idempotence of the request. You can generate a client token from your client and make sure that the client token is unique among different requests. The client token can contain only ASCII characters. Note
If you do not specify this parameter, the system automatically uses the RequestId of the request as the ClientToken. The RequestId of each request is different. |
02fb3da4**** |
| AcceleratorId |
string |
Yes |
The ID of the Global Accelerator instance. |
ga-bp17frjjh0udz4q**** |
| ListenerId |
string |
Yes |
The ID of the listener. |
lsr-bp1s0vzbi5bxlx5**** |
| ForwardingRules |
array<object> |
Yes |
The forwarding rule configurations. |
test |
|
array<object> |
No |
A forwarding rule configuration. |
||
| Priority |
integer |
No |
The priority of the forwarding rule. Valid values: 1 to 10000. A smaller value indicates a higher priority. |
1 |
| RuleConditions |
array<object> |
Yes |
The rule conditions. |
|
|
array<object> |
No |
A rule condition. |
||
| RuleConditionType |
string |
No |
The type of the rule condition. Valid values:
|
Host |
| RuleConditionValue |
string |
No |
The value of the rule condition. This is a JSON-formatted string whose structure depends on the specified RuleConditionType.
|
["www.example.com", "www.aliyun.com"] |
| PathConfig |
object |
No |
The path configuration. Note
This parameter is deprecated. We recommend that you use RuleConditionType and RuleConditionValue to configure rule conditions. |
|
| Values |
array |
No |
The path configuration. A path must be 1 to 128 characters long and must start with a forward slash (/). It can contain letters, digits, dollar signs ($), hyphens (-), underscores (_), periods (.), plus signs (+), forward slashes (/), ampersands (&), tildes (~), at signs (@), colons (:), and apostrophes ('). You can use asterisks (*) and question marks (?) as wildcards. Note
This parameter is deprecated. We recommend that you use RuleConditionType and RuleConditionValue to configure rule conditions. |
|
|
string |
No |
The path configuration. A path must be 1 to 128 characters long and must start with a forward slash (/). It can contain letters, digits, dollar signs ($), hyphens (-), underscores (_), periods (.), plus signs (+), forward slashes (/), ampersands (&), tildes (~), at signs (@), colons (:), and apostrophes ('). You can use asterisks (*) and question marks (?) as wildcards. Note
This parameter is deprecated. We recommend that you use RuleConditionType and RuleConditionValue to configure rule conditions. |
/test |
|
| HostConfig |
object |
No |
The domain name configuration. Note
This parameter is deprecated. We recommend that you use RuleConditionType and RuleConditionValue to configure rule conditions. |
|
| Values |
array |
No |
The domain name configuration. Note
This parameter is deprecated. We recommend that you use RuleConditionType and RuleConditionValue to configure rule conditions. |
|
|
string |
No |
The domain name. A domain name must be 3 to 128 characters long and can contain letters, digits, hyphens (-), and periods (.). You can use asterisks (*) and question marks (?) as wildcards. Note
This parameter is deprecated. We recommend that you use RuleConditionType and RuleConditionValue to configure rule conditions. |
example.com |
|
| RuleActions |
array<object> |
Yes |
The rule actions. |
|
|
array<object> |
No |
A rule action. |
||
| Order |
integer |
Yes |
The priority of the action. Note
This parameter is not in use and can be ignored. |
20 |
| RuleActionType |
string |
Yes |
The type of the rule action. Valid values:
|
ForwardGroup |
| RuleActionValue |
string |
No |
The value for the rule action. This is a JSON-formatted string whose structure depends on the specified RuleActionType. A forwarding rule can have at most one action of type ForwardGroup, Redirect, or FixResponse. Actions of type Rewrite, AddHeader, and RemoveHeader must be specified before a ForwardGroup action.
|
[{"type":"endpointgroup","value":"epg-bp1l49ltx6iengvf2ks5z****"}] |
| ForwardGroupConfig |
object |
No |
The forwarding configuration. Note
This parameter is deprecated. We recommend that you use RuleActionType and RuleActionValue to configure rule actions. |
|
| ServerGroupTuples |
array<object> |
Yes |
The endpoint group configuration. Note
This parameter is deprecated. We recommend that you use RuleActionType and RuleActionValue to configure rule actions. |
|
|
object |
Yes |
The endpoint group configuration. Note
This parameter is deprecated. We recommend that you use RuleActionType and RuleActionValue to configure rule actions. |
||
| EndpointGroupId |
string |
Yes |
The ID of the endpoint group. Note
This parameter is deprecated. We recommend that you use RuleActionType and RuleActionValue to configure rule actions. |
epg-bp1nktp3qgbcq9ih6**** |
| ForwardingRuleName |
string |
No |
The name of the forwarding rule. The name must be 2 to 128 characters long. It must start with a letter or a Chinese character, and can contain letters, Chinese characters, digits, periods (.), underscores (_), and hyphens (-). |
test |
| RuleDirection |
string |
No |
The direction in which the rule takes effect. This parameter does not need to be configured. By default, this parameter is set to request, which indicates that the rule applies to requests. |
request |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The response object. |
||
| RequestId |
string |
The request ID. |
64ADAB1E-0B7F-4FD8-A404-3BECC0E9CCFF |
| ForwardingRules |
array<object> |
The details of the forwarding rules. |
|
|
object |
The details of the forwarding rules. |
||
| ForwardingRuleId |
string |
The forwarding rule ID. |
frule-bp1dii16gu9qdvb34**** |
Examples
Success response
JSON format
{
"RequestId": "64ADAB1E-0B7F-4FD8-A404-3BECC0E9CCFF",
"ForwardingRules": [
{
"ForwardingRuleId": "frule-bp1dii16gu9qdvb34****"
}
]
}
Error codes
|
HTTP status code |
Error code |
Error message |
Description |
|---|---|---|---|
| 400 | NotExist.Listener | The listener does not exist. | The listener does not exist. |
| 400 | NotActive.Listener | The state of the listener is not active. | The listener is unstable. |
| 400 | NotExist.Accelerator | The accelerated instance does not exist. | The GA instance does not exist. |
| 400 | StateError.Accelerator | The state of the accelerated instance is invalid. | The status of the GA instance is invalid. |
| 400 | NotExist.BusinessRegion | The business region does not exist. | The business region does not exist. |
| 400 | NotExist.BasicBandwidthPackage | You must specify the basic bandwidth package. | You must specify the basic bandwidth package. |
| 400 | QuotaExceeded.EndPoint | The maximum number of endpoints is exceeded. | The maximum number of endpoints is exceeded. |
| 400 | Exist.EndpointGroup | The endpoint group already exists. | The endpoint group already exists. |
| 400 | NoPermission.VpcEndpoint | You are not authorized to perform the operation. | The user does not have permissions to create service linked roles. Contact the Alibaba Cloud account owner or the permission administrator to grant the current user AliyunGlobalAccelerationFullAccess or create custom permission policies for service linked role. The following content describes the detailed information about custom permission policies: ServiceName: vpcendpoint.ga.aliyuncs.com. Service linked role name: AliyunServiceRoleForGaVpc. Endpoint Permission: ram:CreateServiceLinkedRole. |
| 400 | QuotaExceeded.ForwardingRule | The number of forwarding rule exceeds the limit. | The number of forwarding rule exceeds the limit. |
| 400 | SystemBusy | System busy, please try again later. | |
| 400 | RepeatPathAndHost.ForwardingRule | The path and host %s are duplicated. | The path and host are duplicated. |
| 400 | QuotaExceeded.RuleConditionConfig | The number of paths and hosts exceeds the limit. | The number of paths and hosts exceeds the limit. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.