调用CreateRule接口创建转发规则。
使用说明
调用该接口创建转发规则时,请注意以下事项:
- 配置Redirect转发动作时,除了HttpCode参数外,其余参数不能全部配置为默认值。
- 同一个转发规则配置多个转发动作时,Rewrite转发动作必须配置ForwardGroup的动作类型。
- CreateRule接口属于异步接口,即系统返回一个实例ID,但该转发规则尚未创建成功,系统后台的创建任务仍在进行。您可以调用ListRules查询转发规则的创建状态:
- 当转发规则处于Provisioning状态时,表示转发规则正在创建中。
- 当转发规则处于Available状态时,表示转发规则创建成功。
- 一条转发规则最多支持添加的条件数(RuleConditions)和动作数(RuleActions)如下:
- 条件数:基础版5条,标准版10条,WAF增强版10条。
- 动作数:基础版3条,标准版5条,WAF增强版5条。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 | 类型 | 是否必选 | 示例值 | 描述 |
---|---|---|---|---|
Action | String | 是 | CreateRule | 要执行的操作。取值:CreateRule。 |
ListenerId | String | 是 | lsr-bp1bpn0kn908w4nbw**** | 应用型负载均衡实例监听ID。 |
ClientToken | String | 否 | 5A2CFF0E-5718-45B5-9D4D-70B3FF3898 | 客户端Token,用于保证请求的幂等性。 由客户端生成该参数值,要保证在不同请求间唯一。ClientToken只支持ASCII字符。 说明 若您未指定,则系统自动使用API请求的RequestId作为ClientToken标识。每次API请求的RequestId不一样。 |
DryRun | Boolean | 否 | false | 是否只预检此次请求,取值:
|
Priority | Integer | 是 | 10 | 规则优先级,取值范围:1~10000。值越小表示优先级越高。 说明 同一个监听内规则优先级必须唯一。 |
Direction | String | 否 | Request | 转发规则的方向。取值:
说明 基础版的ALB实例不支持Response类型。 |
RuleActions.N.FixedResponseConfig.Content | String | 否 | dssacav | 返回的固定内容。最大支持存储1 KB,只支持ASCII字符。 |
RuleActions.N.FixedResponseConfig.ContentType | String | 否 | text/plain | 返回固定内容的格式。 取值:text/plain、text/css、text/html、application/javascript或application/json。 |
RuleActions.N.FixedResponseConfig.HttpCode | String | 否 | HTTP_200 | 返回的HTTP响应码,仅支持HTTP_2xx、HTTP_4xx、HTTP_5xx数字型字符串,x为任意数字。 |
RuleActions.N.ForwardGroupConfig.ServerGroupTuples.N.ServerGroupId | String | 否 | sgp-k86c1ov501id6p**** | 转发到的目的服务器组。 |
RuleActions.N.ForwardGroupConfig.ServerGroupTuples.N.Weight | Integer | 否 | 100 | 权重。取值越大,权重越大,表示转发的访问请求更多。取值范围:0~100。
|
RuleActions.N.ForwardGroupConfig.ServerGroupStickySession.Enabled | Boolean | 否 | false | 是否开启会话保持。取值:
|
RuleActions.N.ForwardGroupConfig.ServerGroupStickySession.Timeout | Integer | 否 | 100 | 超时时间。单位:秒。取值范围:1~86400。默认值:1000。 |
RuleActions.N.InsertHeaderConfig.Key | String | 否 | key | 插入的头字段名称,长度为1~40个字符,支持大小写字母a~z、数字、下划线(_)和短划线(-)。InsertHeaderConfig中的头字段名称不能重复。 说明 不允许将头名称设置为以下字段(不区分大小写): slb-id 、slb-ip 、x-forwarded-for 、x-forwarded-proto 、x-forwarded-eip 、x-forwarded-port 、x-forwarded-client-srcport 、connection 、upgrade 、content-length 、transfer-encoding 、keep-alive 、te 、host 、cookie 、remoteip 、authority 。 |
RuleActions.N.InsertHeaderConfig.Value | String | 否 | UserDefined | 插入的头字段内容。
|
RuleActions.N.InsertHeaderConfig.ValueType | String | 否 | UserDefined | 头字段内容类型。取值:
|
RuleActions.N.Order | Integer | 是 | 1 | 转发规则动作执行的顺序,取值范围:1~50000,按值从小到大执行动作。值不能为空,不能重复。 |
RuleActions.N.RedirectConfig.Host | String | 否 | ${host} | 要跳转的主机地址。取值:
|
RuleActions.N.RedirectConfig.HttpCode | String | 否 | 301 | 跳转方式。取值:301、302、303、307或308。 |
RuleActions.N.RedirectConfig.Path | String | 否 | /test | 要跳转的路径。取值:
|
RuleActions.N.RedirectConfig.Port | String | 否 | 10 | 要跳转的端口。
|
RuleActions.N.RedirectConfig.Protocol | String | 否 | HTTP | 要跳转的协议。
说明 HTTPS监听仅支持跳转HTTPS协议。 |
RuleActions.N.RedirectConfig.Query | String | 否 | ${query} | 要跳转的查询字符串。
|
RuleActions.N.RewriteConfig.Host | String | 否 | www.example.com | 内部跳转的目的主机地址。取值:
|
RuleActions.N.RewriteConfig.Path | String | 否 | /tsdf | 要跳转的路径。取值:
|
RuleActions.N.RewriteConfig.Query | String | 否 | ${query} | 内部跳转的查询字符串。
|
RuleActions.N.Type | String | 是 | ForwardGroup | 动作类型。取值:
转发规则中包括的动作类型:
|
RuleActions.N.TrafficLimitConfig.QPS | Integer | 否 | 100 | 每秒请求次数。取值范围:1~100000。 |
RuleActions.N.TrafficLimitConfig.PerIpQps | Integer | 否 | 80 | 单IP每秒请求次数。 取值范围:1 ~ 100000。 说明 如果同时配置QPS参数,PerIpQps参数的取值必须小于QPS参数的取值。 |
RuleActions.N.TrafficMirrorConfig.TargetType | String | 否 | ForwardGroupMirror | 镜像的目标类型。取值:
|
RuleActions.N.TrafficMirrorConfig.MirrorGroupConfig.ServerGroupTuples.N.ServerGroupId | String | 否 | sgp-00mkgijak0w4qgz9**** | 服务器组ID。 |
RuleActions.N.CorsConfig.AllowOrigin.N | String | 否 | http://example.com | 允许访问的来源。支持配置为
|
RuleActions.N.CorsConfig.AllowMethods.N | String | 否 | GET | 选择跨域访问时允许的HTTP方法。取值:
|
RuleActions.N.CorsConfig.AllowHeaders.N | String | 否 | test_123 | 允许跨域的Header列表。支持配置为 |
RuleActions.N.CorsConfig.ExposeHeaders.N | String | 否 | test_123 | 允许暴露的Header列表。支持配置为 |
RuleActions.N.CorsConfig.AllowCredentials | String | 否 | on | 是否允许携带凭证信息。取值:
|
RuleActions.N.CorsConfig.MaxAge | Long | 否 | 1000 | 预检请求在浏览器的最大缓存时间,单位:秒。 取值范围:-1~172800。 |
RuleConditions.N.CookieConfig.Values.N.Key | String | 否 | test | Cookie键。
|
RuleConditions.N.CookieConfig.Values.N.Value | String | 否 | test | Cookie值。
|
RuleConditions.N.HeaderConfig.Key | String | 否 | Port | 头字段键。
|
RuleConditions.N.HeaderConfig.Values.N | String | 否 | 5006 | 头字段值。同一个转发规则条件内头字段值不能重复。
|
RuleConditions.N.HostConfig.Values.N | String | 否 | www.example.edu | 主机名。一个转发规则条件中只能有一个主机名,并且取值不能重复。
|
RuleConditions.N.MethodConfig.Values.N | String | 否 | PUT | 请求方法。 取值:HEAD、GET、POST、OPTIONS、PUT、PATCH、DELETE。 |
RuleConditions.N.PathConfig.Values.N | String | 否 | /test | 转发路径。取值范围:
|
RuleConditions.N.QueryStringConfig.Values.N.Key | String | 否 | test | 查询字符串键。
|
RuleConditions.N.QueryStringConfig.Values.N.Value | String | 否 | test | 查询字符串值。
|
RuleConditions.N.Type | String | 是 | Host | 转发规则类型。取值:
|
RuleConditions.N.SourceIpConfig.Values.N | String | 否 | 192.168.0.0/32 | 添加一个或多个IP地址或者IP地址段。 |
RuleName | String | 是 | rule-doc | 转发规则名称。
|
返回数据
名称 | 类型 | 示例值 | 描述 |
---|---|---|---|
JobId | String | 72dcd26b-f12d-4c27-b3af-18f6aed5**** | 异步任务ID。 |
RequestId | String | 365F4154-92F6-4AE4-92F8-7FF34B540750 | 请求ID。 |
RuleId | String | rule-a3x3pg1yohq3lq**** | 转发规则ID。 |
示例
请求示例
http(s)://[Endpoint]/?Action=CreateRule
&ListenerId=lsr-bp1bpn0kn908w4nbw****
&ClientToken=5A2CFF0E-5718-45B5-9D4D-70B3FF3898
&DryRun=false
&Priority=10
&Direction=Request
&RuleActions=[{"FixedResponseConfig":{"Content":"dssacav","ContentType":"text/plain","HttpCode":"HTTP_200"},"ForwardGroupConfig":{"ServerGroupTuples":[{"ServerGroupId":"sgp-k86c1ov501id6p****","Weight":100}],"ServerGroupStickySession":{"Enabled":false,"Timeout":100}},"InsertHeaderConfig":{"Key":"key","Value":"UserDefined","ValueType":"UserDefined"},"Order":1,"RedirectConfig":{"Host":"${host}","HttpCode":"301","Path":"/test","Port":"10","Protocol":"HTTP","Query":"${query}"},"RewriteConfig":{"Host":"www.example.com","Path":"/tsdf","Query":"${query}"},"Type":"ForwardGroup","TrafficLimitConfig":{"QPS":100,"PerIpQps":80},"TrafficMirrorConfig":{"TargetType":"ForwardGroupMirror","MirrorGroupConfig":{"ServerGroupTuples":[{"ServerGroupId":"sgp-00mkgijak0w4qgz9****"}]}},"CorsConfig":{"AllowOrigin":["http://example.com"],"AllowMethods":["GET"],"AllowHeaders":["test_123"],"ExposeHeaders":["test_123"],"AllowCredentials":"on","MaxAge":1000}}]
&RuleConditions=[{"CookieConfig":{"Values":[{"Key":"test","Value":"test"}]},"HeaderConfig":{"Key":"Port","Values":["5006"]},"HostConfig":{"Values":["www.example.edu"]},"MethodConfig":{"Values":["PUT"]},"PathConfig":{"Values":["/test"]},"QueryStringConfig":{"Values":[{"Key":"test","Value":"test"}]},"Type":"Host","SourceIpConfig":{"Values":["192.168.0.0/32"]}}]
&RuleName=rule-doc
&公共请求参数
正常返回示例
XML
格式
HTTP/1.1 200 OK
Content-Type:application/xml
<CreateRuleResponse>
<JobId>72dcd26b-f12d-4c27-b3af-18f6aed5****</JobId>
<RequestId>365F4154-92F6-4AE4-92F8-7FF34B540750</RequestId>
<RuleId>rule-a3x3pg1yohq3lq****</RuleId>
</CreateRuleResponse>
JSON
格式
HTTP/1.1 200 OK
Content-Type:application/json
{
"JobId" : "72dcd26b-f12d-4c27-b3af-18f6aed5****",
"RequestId" : "365F4154-92F6-4AE4-92F8-7FF34B540750",
"RuleId" : "rule-a3x3pg1yohq3lq****"
}
错误码
HttpCode | 错误码 | 错误信息 | 描述 |
---|---|---|---|
400 | IncorrectStatus.Listener | The status of %s [%s] is incorrect. | 资源%s [%s]的状态无效。 |
400 | OperationDenied.SameGroupForForwardAndMirrorAction | The operation is not allowed because of %s. | 操作被拒绝,原因是%s。 |
400 | OperationDenied.IpGroupCanNotUsedForMirrorAction | The operation is not allowed because of %s. | 操作被拒绝,原因是%s。 |
400 | OperationDenied.GRPCServerGroup | The operation is not allowed because of %s. | 操作被拒绝,原因是%s。 |
400 | Conflict.Priority | There is already %s having the same configuration with %s. | %s冲突,已经存在同配置的%s。 |
400 | ResourceQuotaExceeded.LoadBalancerRulesNum | The quota of %s is exceeded for resource %s, usage %s/%s. | 配额%s已超额度限制,资源是%s,目前已使用%s,配额为%s。 |
400 | ResourceQuotaExceeded.ServerGroupAttachedNum | The quota of %s is exceeded for resource %s, usage %s/%s. | 配额%s已超额度限制,资源是%s,目前已使用%s,配额为%s。 |
400 | ResourceQuotaExceeded.LoadBalancerServersNum | The quota of %s is exceeded for resource %s, usage %s/%s. | 配额%s已超额度限制,资源是%s,目前已使用%s,配额为%s。 |
400 | ResourceQuotaExceeded.ServerAddedNum | The quota of %s is exceeded for resource %s, usage %s/%s. | 配额%s已超额度限制,资源是%s,目前已使用%s,配额为%s。 |
400 | QuotaExceeded.RuleWildcardsNum | The quota of %s is exceeded, usage %s/%s. | 配额%s已超额度限制,目前已使用%s,配额为%s。 |
400 | QuotaExceeded.RuleMatchEvaluationsNum | The quota of %s is exceeded, usage %s/%s. | 配额%s已超额度限制,目前已使用%s,配额为%s。 |
400 | QuotaExceeded.RuleActionsNum | The quota of %s is exceeded, usage %s/%s. | 配额%s已超额度限制,目前已使用%s,配额为%s。 |
400 | Mismatch.Protocol | The %s is mismatched for %s and %s. | %s在%s和%s中不匹配。 |
400 | Mismatch.VpcId | The %s is mismatched for %s and %s. | %s在%s和%s中不匹配。 |
400 | OperationDenied.RewriteMissingForwardGroup | The operation is not allowed because of RewriteMissingForwardGroup. | 操作被拒绝,原因是RewriteMissingForwardGroup。 |
400 | ResourceInConfiguring.Listener | The specified listener is being configured, please try again later. | 资源正在变配中,请稍后重试。 |
404 | ResourceNotFound.Listener | The specified resource %s is not found. | 资源%s不存在。 |
404 | ResourceNotFound.ServerGroup | The specified resource %s is not found. | 资源%s不存在。 |
访问错误中心查看更多错误码。