All Products
Search
Document Center

Server Load Balancer:CreateRules

Last Updated:Dec 24, 2024

Creates multiple forwarding rules at a time.

Operation description

When you call this operation, take note of the following limits:

  • When you configure the Redirect action, do not use the default values for parameters other than HttpCode.

  • If you specify multiple actions in a forward rule, you must specify the ForwardGroup parameter along with the Rewrite parameter.

  • CreateRules is an asynchronous operation. After a request is sent, the system returns a request ID and runs the task in the background. You can call the ListRules operation to query the status of the forwarding rules.

    • If the forwarding rules are in the Provisioning state, the forwarding rules are being created.
    • If the forwarding rules are in the Available state, the forwarding rules are created.
  • You can set RuleConditions and RuleActions to add conditions and actions to a forwarding rule. Take note of the following limits on the number of conditions and the number of actions in each forwarding rule:

    • Conditions: 5 for each basic ALB instance, 10 for each standard ALB instance, and 10 for each WAF-enabled ALB instance.
    • Actions: 3 for each basic ALB instance, 5 for each standard ALB instance, and 5 for each WAF-enabled ALB instance.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
alb:CreateRulescreate
*LoadBalancer
acs:alb:{#regionId}:{#accountId}:loadbalancer/{#loadbalancerId}
*ServerGroup
acs:alb:{#regionId}:{#accountId}:servergroup/{#servergroupId}
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
ListenerIdstringYes

The ID of the Application Load Balancer (ALB) instance.

lsr-bp1bpn0kn908w4nbw****
ClientTokenstringNo

The client token that is used to ensure the idempotence of the request.

You can use the client to generate the token, but you must make sure that the token is unique among different requests. The token can contain only ASCII characters.

Note If you do not specify this parameter, the system automatically uses the request ID as the client token. The request ID may be different for each request.
5A2CFF0E-5718-45B5-9D4D-70B3FF3898
DryRunbooleanNo

Specifies whether to perform only a dry run, without performing the actual request. Valid values:

  • true: performs a dry run. The system checks the request for potential issues, including missing parameter values, incorrect request syntax, and service limits. If the request fails the dry run, an error code is returned. If the request passes the dry run, the DryRunOperation error code is returned.
  • false (default): performs a dry run and sends the request. If the request passes the dry run, a 2xx HTTP status code is returned and the operation is performed.
false
Rulesarray<object>Yes

The forwarding rules.

objectYes
PriorityintegerYes

The priority of the forwarding rule.

10
RuleActionsarray<object>Yes

The actions of the forwarding rule.

objectYes
FixedResponseConfigobjectNo

The configuration of the custom response.

ContentstringNo

The content of the custom response.

dssacav
ContentTypestringNo

The format of the content.

text/plain
HttpCodestringNo

The HTTP status code in responses.

HTTP_200
ForwardGroupConfigobjectNo

The configuration of the server group.

ServerGroupTuplesarray<object>No

The server groups to which requests are forwarded.

objectNo
ServerGroupIdstringNo

The server group to which requests are forwarded.

sgp-k86c1ov501id6p****
WeightintegerNo

The weight of the server group.

100
ServerGroupStickySessionobjectNo

The configuration of session persistence for the server groups.

EnabledbooleanNo

Specifies whether to enable session persistence.

false
TimeoutintegerNo

The timeout period of sessions.

2
InsertHeaderConfigobjectNo

The key of the header to be inserted.

KeystringNo

The key of the header.

key
ValuestringNo

The value of the header to be inserted.

UserDefined
ValueTypestringNo

The type of the header.

UserDefined
OrderintegerYes

The priority of the action.

1
RedirectConfigobjectNo

The configuration of the redirect action.

HoststringNo

The hostname to which requests are forwarded.

www.example.com
HttpCodestringNo

The HTTP status code that indicates the redirect type.

301
PathstringNo

The URL to which requests are redirected.

/test
PortstringNo

The port to which requests are distributed.

10
ProtocolstringNo

The redirect protocol.

HTTP
QuerystringNo

The query string to which requests are redirected.

quert
RewriteConfigobjectNo

The configuration of the rewrite action.

HoststringNo

The hostname to which requests are rewritten.

www.example.com
PathstringNo

The URL to which requests are redirected.

/tsdf
QuerystringNo

The query string of the URL to which requests are forwarded.

quedsa
TypestringYes

The action.

ForwardGroup
TrafficLimitConfigobjectNo

The configuration of traffic throttling.

QPSintegerNo

The number of queries per second (QPS). Valid values: 1 to 1000000.

100
PerIpQpsintegerNo

The number of requests per IP address. Value values: 1 to 1000000.

Note If both the QPS and PerIpQps parameters are specified, the value of the QPS parameter is smaller than the value of the PerIpQps parameter.
80
TrafficMirrorConfigobjectNo

The configuration of traffic mirroring.

TargetTypestringNo

The type of target to which network traffic is mirrored.

ForwardGroupMirror
MirrorGroupConfigobjectNo

The configuration of the server group to which traffic is mirrored.

ServerGroupTuplesarray<object>No

The server group to which traffic is mirrored.

objectNo

The server group to which traffic is mirrored.

ServerGroupIdstringNo

The server group ID.

srg-00mkgijak0w4qgz9****
RemoveHeaderConfigobjectNo

The HTTP header to be removed.

KeystringNo

The key of the header to be removed.

test
CorsConfigobjectNo

The CORS configuration.

AllowOriginarrayNo

The trusted origins of CORS requests.

stringNo
http://example.com
AllowMethodsarrayNo

The trusted HTTP methods of CORS requests.

stringNo
GET
AllowHeadersarrayNo

The trusted headers of CORS requests.

stringNo
test_123
ExposeHeadersarrayNo

The headers that can be exposed.

stringNo
test_123
AllowCredentialsstringNo

Specifies whether to allow credentials to be carried in CORS requests.

on
MaxAgelongNo

The maximum cache time of dry run requests in the browser.

1000
RuleConditionsarray<object>Yes

The match conditions of the forwarding rule.

objectYes
CookieConfigobjectNo

The key-value pairs of the cookie.

Valuesarray<object>No

The cookie value.

objectNo
KeystringNo

The cookie key.

test
ValuestringNo

The cookie value.

test
HeaderConfigobjectNo

The configuration of the header.

KeystringNo

The header key.

Port
ValuesarrayNo

The header values.

stringNo
5006
HostConfigobjectNo

The configuration of the hosts.

ValuesarrayNo

The hostname.

stringNo
www.example.com
MethodConfigobjectNo

The configurations of the request methods.

ValuesarrayNo

The request methods.

stringNo
PUT
PathConfigobjectNo

The configurations of the forwarding URLs.

ValuesarrayNo

The forwarding URLs.

stringNo
/test
QueryStringConfigobjectNo

The configurations of the query strings.

Valuesarray<object>No

The configurations of the query string.

objectNo
KeystringNo

They key of the query string.

test
ValuestringNo

The value of the query string.

test
ResponseHeaderConfigobjectNo

The configuration of the header.

KeystringNo

The key of the header.

Port
ValuesarrayNo

The value of the header.

ValuestringNo
5006
ResponseStatusCodeConfigobjectNo

The configurations of the response status codes.

ValuesarrayNo

The response status codes.

ValuestringNo
200
TypestringYes

The type of forwarding rule.

Host
SourceIpConfigobjectNo

Traffic matching based on source IP addresses.

ValuesarrayNo

Traffic matching based on source IP addresses.

stringNo
192.168.0.0/32
RuleNamestringYes

The name of the forwarding rule.

test
DirectionstringNo

The direction to which the forwarding rule is applied.

Request
Tagarray<object>No

The tags.

objectNo

The tag.

KeystringNo

The tag key. The tag key can be up to 128 characters in length. It cannot start with aliyun or acs: and cannot contain http:// or https://.

env
ValuestringNo

The tag value. The tag value can be up to 128 characters in length. It cannot start with aliyun or acs: and cannot contain http:// or https://.

product

Response parameters

ParameterTypeDescriptionExample
object

Creates one or more forwarding rules at a time.

JobIdstring

The ID of the asynchronous task.

72dcd26b-f12d-4c27-b3af-18f6aed5****
RequestIdstring

The request ID.

365F4154-92F6-4AE4-92F8-7FF34B540710
RuleIdsarray<object>

The priority of the forwarding rule. Valid values: 1 to 10000. A lower value specifies a higher priority.

Note The priorities of the forwarding rules created for the same listener is unique.
RuleIdobject
RuleIdstring

The forwarding rule ID.

rule-a3x3pg1yohq3lq****
Priorityinteger

The priority of the forwarding rule. Valid values: 1 to 10000. A smaller value indicates a higher priority.

Note The priorities of the forwarding rules created for the same listener must be unique.
10

Examples

Sample success responses

JSONformat

{
  "JobId": "72dcd26b-f12d-4c27-b3af-18f6aed5****",
  "RequestId": "365F4154-92F6-4AE4-92F8-7FF34B540710",
  "RuleIds": [
    {
      "RuleId": "rule-a3x3pg1yohq3lq****",
      "Priority": 10
    }
  ]
}

Error codes

HTTP status codeError codeError messageDescription
400IncorrectStatus.ListenerThe status of %s [%s] is incorrect.-
400OperationDenied.IpGroupCanNotUsedForMirrorActionThe operation is not allowed because of %s.The operation is not allowed because of %s.
400OperationDenied.SameGroupForForwardAndMirrorActionThe operation is not allowed because of %s.The operation is not allowed because of %s.
400OperationDenied.GRPCServerGroupThe operation is not allowed because of %s.-
400Conflict.PriorityThere is already %s having the same configuration with %s.-
400ResourceQuotaExceeded.LoadBalancerRulesNumThe quota of %s is exceeded for resource %s, usage %s/%s.-
400ResourceQuotaExceeded.ServerGroupAttachedNumThe quota of %s is exceeded for resource %s, usage %s/%s.-
400ResourceQuotaExceeded.LoadBalancerServersNumThe quota of %s is exceeded for resource %s, usage %s/%s.-
400ResourceQuotaExceeded.ServerAddedNumThe quota of %s is exceeded for resource %s, usage %s/%s.-
400QuotaExceeded.RuleWildcardsNumThe quota of %s is exceeded, usage %s/%s.The quota of %s is exceeded, usage %s/%s.
400QuotaExceeded.RuleMatchEvaluationsNumThe quota of %s is exceeded, usage %s/%s.-
400QuotaExceeded.RuleActionsNumThe quota of %s is exceeded, usage %s/%s.The quota of %s is exceeded. Usage: %s/%s.
400Mismatch.VpcIdThe %s is mismatched for %s and %s.The %s is mismatched for %s and %s.
400Mismatch.ProtocolThe %s is mismatched for %s and %s.The %s is mismatched for %s and %s.
400OperationDenied.RewriteMissingForwardGroupThe operation is not allowed because of RewriteMissingForwardGroup.The operation is not allowed because rewrite is missing the forward group.
400OperationDenied.MirrorActionSupportHttpGroupOnlyThe operation is not allowed because of MirrorActionSupportHttpGroupOnly.-
400OperationDenied.ProtocolMustSameForForwardGroupActionThe operation is not allowed because of ProtocolMustSameForForwardGroupAction.-
404ResourceNotFound.ListenerThe specified resource %s is not found.-
404ResourceNotFound.ServerGroupThe specified resource %s is not found.-

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-12-11The Error code has changedView Change Details
2024-11-28The Error code has changedView Change Details
2024-09-23The Error code has changedView Change Details
2024-01-18The Error code has changedView Change Details
2023-11-09The Error code has changedView Change Details