Skip to Content

Create forwarding rules for application load balancer - CreateRule

Overview

Create a forwarding rule for the application load balancer listener

Definition

Public Parameters

Parameter NameTypeDescription InformationRequired
ActionstringCorresponding API command name, the current API is CreateRule.Yes
PublicKeystringThe user’s public key can be obtained from ConsoleYes
SignaturestringUser signature generated based on public key and API command, see Signature AlgorithmYes

Request Parameters

Parameter NameTypeDescription InformationRequired
RegionstringRegion. See List of Regions and Availability ZonesYes
ProjectIdstringProject ID. If not filled in, the default project is used, sub-accounts must be filled in. Please refer to the GetProjectList interface.Yes
LoadBalancerIdstringID of the Load Balancing InstanceYes
ListenerIdstringListener’s IDYes
RuleConditions.N.TypestringMatching condition type. Limited enumeration values: “Host”/“Path”.Yes
RuleConditions.N.HostConfig.MatchModestringMatching method. Limited enumeration values: ‘Regular’/‘Wildcard’, default value: ‘Regular’.No
Values.NstringValue. Currently, only arrays of length 1 are supported; the value must meet the conditions of the relevant matching method; it is mandatory to fill in when matching domain names.No
Values.NstringValue. Currently only supports an array length of 1; the value must meet relevant conditions; must be filled in when path matching.No
RuleActions.N.TypestringAction Type. Limited enumeration values: “Forward”, “InsertHeader”, “Cors”, “FixedResponse”, “RemoveHeader”. Only the structure corresponding to Type will be processed.Yes
Targets.N.IdstringThe identifier ID of the backend service node being forwarded. It is limited to the service node pool of the listener; the array length can be 0; when the array length of the configured forwarding service node is not 0, the ID is required.No
Targets.N.WeightintThe weight of the backend service node being forwarded. Only valid when the load balancing algorithm of the listener is weighted round robin.No
RuleActions.N.OrderintThe execution order of forwarding rule actions ranges from 1 to 1000, with actions executed from smallest to largest value. The value cannot be empty or duplicated.

Forward and FixedResponse types of actions do not consider Order and are executed last.
No
RuleActions.N.InsertHeaderConfig.KeystringThe inserted header field name must be 1 to 40 characters long and can include uppercase and lowercase letters a-z, numbers, underscores (_), and hyphens (-). The header field name cannot be used repeatedly in InsertHeader.

The header field cannot use the following (case insensitive):

x-real-ip, x-forwarded-for, x-forwarded-proto, x-forwarded-srcport, ucloud-alb-trace, connection, upgrade, content-length, transfer-encoding, keep-alive, te, host, cookie, remoteip, authority.
No
RuleActions.N.InsertHeaderConfig.ValueTypestringHeader field content type. Values:
UserDefined: User specified.

ReferenceHeader: Referencing a field from the user’s request header.

SystemDefined: System defined.
No
RuleActions.N.InsertHeaderConfig.ValuestringContent of the inserted header field.

When ValueType is SystemDefined, the values are as follows:
ClientSrcPort: Client port.
ClientSrcIp: Client IP address.
Protocol: Protocol of the client’s request (HTTP or HTTPS).
RuleID: ID of the forwarding rule hit by the client’s request.
ALBID: ALB ID.
ALBPort: ALB port.

When ValueType is UserDefined:

You can customize the header field content, with a length limit of 1~128 characters, supporting printable characters in the ASCII range where ch >= 32 && ch < 127, excluding $.

When ValueType is ReferenceHeader:

You can reference a specific field from the request header fields, with a length limit of 1~128 characters, supporting lowercase letters a~z, numbers, hyphens (-), and underscores (_).
No
RuleActions.N.RemoveHeaderConfig.KeystringThe header field names to be deleted, currently only the following default configured fields can be deleted

X-Real-IP, X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-SrcPort
No
AllowOrigin.NstringAllowed access source list. Supports configuring a single element , or one or more values.

A single value must start with http:// or https://, followed by a correct domain name or a primary wildcard domain. (Example: http://
.test.abc.example.com)
A single value can omit the port or specify a port, with a port range of 1~65535.
Supports up to 5 values.
No
AllowHeaders.NstringList of Headers allowed for cross-origin. Supports configuration as * or one or more value entries. A single value entry may only contain uppercase and lowercase letters, numbers, and cannot start or end with an underscore (_) or hyphen (-), with a maximum length limit of 32 characters. Supports up to 20 entries.No
ExposeHeaders.NstringList of allowed exposed Headers. Supports configuration as * or one or more value(s). A single value is only allowed to contain uppercase and lowercase letters, numbers, and cannot start or end with an underscore (_) or hyphen (-), with a maximum length of 32 characters. Supports up to 20 values.No
AllowMethods.NstringSelect the allowed HTTP methods for cross-domain access. Values:

GET.
POST.
PUT.
DELETE.
HEAD.
OPTIONS.
PATCH.
No
RuleActions.N.CorsConfig.AllowCredentialsstringAllow carrying credential information. Values:

on: Yes.
off: No.
No
RuleActions.N.CorsConfig.MaxAgeintMaximum cache time for preflight requests in the browser, in seconds.

Value range: -1~172800.
No
RuleActions.N.FixedResponseConfig.HttpCodeintReturned HTTP response codes, only supports 2xx, 4xx, 5xx numbers, where x is any digit.No
RuleActions.N.FixedResponseConfig.ContentstringReturned fixed content. Supports storage up to 1 KB, only supports printable characters within the ASCII code range ch >= 32 && ch < 127, excluding $.No
PassbooleanWhether the rule is ignored when the service node to be forwarded is empty. The default value is true.No

Response Field

Field NameTypeDescription InformationRequired
RetCodeintReturn status code. If it is 0, it means successful return. If it is not 0, it means failure.Yes
ActionstringOperation command name.Yes
MessagestringReturns an error message, providing detailed description when RetCode is non-zero.No
RuleIdstringID of the forwarding ruleYes

Example

Request Example

https://api.genesissai.com/?Action=CreateRule &Region=cn-zj &ProjectId=KkLjsPqn &LoadBalancerId=TpQFMTyp &ListenerId=TBLRaFqM &RuleConditions.n.Type=OwQlzYTk &RuleActions.n.Type=CdXoaIEM &RuleConditions.n.HostConfig.MatchMode=PVAsSDML &RuleConditions.n.HostConfig.Values.n=leqEAWWl &RuleConditions.n.PathConfig.Values.n=PwuAChmC &RuleActions.n.ForwardConfig.Targets.n.Id=kJkvikIW &RuleActions.n.ForwardConfig.Targets.n.Weight=2 &Pass=true &RuleActions.n.Order=8 &RuleActions.n.InsertHeaderConfig.Key=FggaGvNf &RuleActions.n.InsertHeaderConfig.ValueType=fGRElWKu &RuleActions.n.InsertHeaderConfig.Value=tONXuVLL &RuleActions.n.RemoveHeaderConfig.Key=yPJEuNJS &RuleActions.n.CorsConfig.AllowOrigin.n=LIsTRKRs &RuleActions.n.CorsConfig.AllowHeaders.n=hxwaXQFI &RuleActions.n.CorsConfig.ExposeHeaders.n=umwnQzxR &RuleActions.n.CorsConfig.AllowMethods.n=RNCUBGzF &RuleActions.n.CorsConfig.AllowCredentials=CPBenoTf &RuleActions.n.CorsConfig.MaxAge=3 &RuleActions.n.FixedResponseConfig.HttpCode=8 &RuleActions.n.FixedResponseConfig.Content=WzivkLDY &RuleActions.n.Order=9 &RuleActions.n.InsertHeaderConfig.Key=ejZeJwqb &RuleActions.n.InsertHeaderConfig.ValueType=lCNCsmJE &RuleActions.n.InsertHeaderConfig.Value=MkjLDVpA &RuleActions.n.RemoveHeaderConfig.Key=zOtodzbH &RuleActions.n.CorsConfig.AllowOrigin.n=GgnvyDiy &RuleActions.n.CorsConfig.AllowHeaders.n=XEcqLwCf &RuleActions.n.CorsConfig.ExposeHeaders.n=HJQMCfUp &RuleActions.n.CorsConfig.AllowMethods.n=MkuDHUmA &RuleActions.n.CorsConfig.AllowCredentials=bxzcboba &RuleActions.n.CorsConfig.MaxAge=6 &RuleActions.n.FixedResponseConfig.HttpCode=8 &RuleActions.n.FixedResponseConfig.Content=DChjvFbl

Response Example

{ "Action": "CreateRuleResponse", "RetCode": 0, "RuleId": "qZjWGzsa" }