All Products
Search
Document Center

Resource Orchestration Service:ALIYUN::ALB::Rule

Last Updated:Dec 04, 2025

The ALIYUN::ALB::Rule type creates a forwarding rule.

Syntax

{
  "Type": "ALIYUN::ALB::Rule",
  "Properties": {
    "RuleActions": List,
    "Priority": Integer,
    "RuleConditions": List,
    "Direction": String,
    "RuleName": String,
    "ListenerId": String
  }
}

Properties

Property

Type

Required

Allow updates

Description

Constraints

ListenerId

String

Yes

No

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

None

Priority

Integer

Yes

Yes

The priority of the forwarding rule.

Valid values: 1 to 10,000. A smaller value indicates a higher priority.

Note

The priority of each forwarding rule within the same listener must be unique.

RuleActions

List

Yes

Yes

The actions of the forwarding rule.

For more information, see RuleActions properties.

RuleConditions

List

Yes

Yes

The conditions of the forwarding rule.

For more information, see RuleConditions properties.

RuleName

String

Yes

Yes

The name of the forwarding rule.

The name must be 2 to 128 characters in length. It must start with a letter or a Chinese character and can contain letters, Chinese characters, digits, periods (.), underscores (_), and hyphens (-).

Direction

String

No

No

The direction of the forwarding rule.

Valid values:

  • Request: The rule is applied to requests.

  • Response: response.

RuleActions syntax

"RuleActions": [
  {
    "Order": Integer,
    "FixedResponseConfig": Map,
    "Type": String,
    "RedirectConfig": Map,
    "ForwardGroupConfig": Map,
    "InsertHeaderConfig": Map,
    "RewriteConfig": Map,
    "TrafficMirrorConfig": Map,
    "TrafficLimitConfig": Map,
    "RemoveHeaderConfig": Map,
    "CorsConfig": Map
  }
]

RuleActions properties

Property

Type

Required

Updatable

Description

Constraints

Order

Integer

Yes

Yes

The order in which the forwarding rule actions are performed.

Valid values: 1 to 50,000. Actions are performed in ascending order of value.

Note

The value must be unique.

Type

String

Yes

Yes

The action type.

Valid values:

  • ForwardGroup: Forwards requests to multiple vServer groups.

  • Redirect: To perform a redirection.

  • FixedResponse: Returns a fixed response.

  • rewrite: rewrite.

  • InsertHeader: Inserts a header field.

CorsConfig

Map

No

Yes

The cross-domain configuration.

For more information, see CorsConfig properties.

FixedResponseConfig

Map

No

Yes

The fixed response configuration.

For more information, see FixedResponseConfig properties.

ForwardGroupConfig

Map

No

Yes

The forwarding group configuration.

For more information, see ForwardGroupConfig properties.

InsertHeaderConfig

Map

No

Yes

The configuration for inserting a header field.

For more information, see InsertHeaderConfig properties.

RedirectConfig

Map

No

Yes

The redirection configuration.

For more information, see RedirectConfig properties.

RemoveHeaderConfig

Map

No

Yes

The configuration for deleting a header field.

For more information, see RemoveHeaderConfig properties.

RewriteConfig

Map

No

Yes

The rewrite configuration.

For more information, see RewriteConfig properties.

TrafficLimitConfig

Map

No

Yes

The traffic throttling configuration.

For more information, see TrafficLimitConfig properties.

TrafficMirrorConfig

Map

No

Yes

The traffic mirroring configuration.

For more information, see TrafficMirrorConfig properties.

FixedResponseConfig syntax

"FixedResponseConfig": {
  "HttpCode": String,
  "ContentType": String,
  "Content": String
}

FixedResponseConfig properties

Property

Type

Required

Updatable

Description

Constraints

Content

String

No

Yes

The content of the fixed response.

The content can be up to 1 KB in size and must consist of ASCII characters.

ContentType

String

No

Yes

The format of the fixed response.

Valid values:

  • text/plain

  • text/css

  • text/html

  • application/javascript

  • application/json

HttpCode

String

No

Yes

The HTTP response code.

Valid values are strings in the format of HTTP_2xx, HTTP_4xx, and HTTP_5xx, where x is any digit.

RedirectConfig syntax

"RedirectConfig": {
  "Path": String,
  "HttpCode": Integer,
  "Query": String,
  "Port": String,
  "Host": String,
  "Protocol": String
}

RedirectConfig properties

Property

Type

Required

Updatable

Description

Constraints

Host

String

No

Yes

The host to which requests are redirected.

Valid values:

  • ${host} (default): This value cannot be concatenated with other strings.

  • Other values. The value must meet the following requirements:

    • The hostname must be 3 to 128 characters in length and can contain lowercase letters, digits, hyphens (-), periods (.), asterisks (*), and question marks (?).

    • The hostname must contain at least one period (.). The period cannot be the first or last character.

    • The rightmost domain label can contain only letters and wildcard characters. It cannot contain digits or hyphens (-).

    • A hyphen (-) cannot be the first or last character of a domain label.

    • An asterisk (*) or a question mark (?) can appear anywhere in a domain label.

HttpCode

Integer

No

Yes

The redirection method.

Valid values:

  • 301

  • 302

  • 303

  • 307

  • 308

Path

String

No

Yes

The path to which requests are redirected.

Valid values:

  • ${path} (default): You can reference the ${host}, ${protocol}, and ${port} variables. Each variable can appear at most once. You can use these variables together or concatenate them with a supported string.

  • Other values. The value must meet the following requirements:

    • The path must be 1 to 128 characters in length.

    • It must start with a forward slash (/) and can contain letters, digits, the asterisk (*), the question mark (?), and the following special characters: $-_.+/&~@:. It cannot contain the following characters: %#;!()[]^,".

    • English letters are case-sensitive.

Port

String

No

Yes

The port to which requests are redirected.

Valid values:

  • ${port} (default): This value cannot be used with other strings.

  • Other valid values: 1 to 63335.

Protocol

String

No

Yes

The protocol to which requests are redirected.

Valid values:

  • ${protocol} (default): This value cannot be concatenated with other strings.

  • HTTP

  • HTTPS

    Note

    HTTPS listeners only support redirection to HTTPS.

Query

String

No

Yes

The query string to which requests are redirected.

Valid values:

  • ${query} (default): You can reference the ${host}, ${protocol}, and ${port} variables. Each variable can appear at most once. You can use these variables together or concatenate them with a supported string from the list of valid values below.

  • Other values. The value must meet the following requirements:

    • The string must be 1 to 128 characters in length.

    • It cannot contain spaces or the following special characters: #[]{}\|<>&.

    • It can contain only lowercase letters.

ForwardGroupConfig syntax

"ForwardGroupConfig": {
  "ServerGroupTuples": List,
  "ServerGroupStickySession": Map
}

ForwardGroupConfig properties

Property

Type

Required

Updatable

Description

Constraints

ServerGroupStickySession

Map

No

Yes

The session persistence configuration.

For more information, see ServerGroupStickySession properties.

ServerGroupTuples

List

No

Yes

The list of destination vServer groups.

For more information, see ServerGroupTuples properties.

ServerGroupStickySession syntax

"ServerGroupStickySession": {
 "Enabled": Boolean,
  "Timeout": Integer
}

ServerGroupStickySession properties

Property

Type

Required

Updatable

Description

Constraints

Enabled

Boolean

No

Yes

Specifies whether to enable session persistence.

Valid values:

  • true: Enables session persistence.

  • false (default): Disables session persistence.

Timeout

Integer

No

Yes

The timeout period.

Unit: seconds. Valid values: 1 to 86400.

ServerGroupTuples syntax

"ServerGroupTuples": [
  {
    "ServerGroupId": String
  }
]

ServerGroupTuples properties

Property

Type

Required

Updatable

Description

Constraints

ServerGroupId

String

Yes

Yes

The ID of the destination vServer group.

None

InsertHeaderConfig syntax

"InsertHeaderConfig": {
  "ValueType": String,
  "Value": String,
  "Key": String
}

InsertHeaderConfig properties

Property

Type

Required

Updatable

Description

Constraints

Key

String

No

Yes

The name of the header field to insert.

The name must be 1 to 40 characters in length and can contain letters, digits, underscores (_), and hyphens (-). The header name in InsertHeaderConfig must be unique.

Note

The header name cannot be set to any of the following values (case-insensitive): 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.

Value

String

No

Yes

The content of the header field to insert.

Valid values:

  • If ValueType is set to SystemDefined:

    • ClientSrcPort: The client port.

    • ClientSrcIp: The client IP address.

    • Protocol: The protocol of the client request (HTTP or HTTPS).

    • SLBId: The ID of the ALB instance.

    • SLBPort: The listening port of the ALB instance.

  • If ValueType is set to ReferenceHeader:

    You can reference a field in the request header. The value is 1 to 128 characters in length and can contain lowercase letters, digits, hyphens (-), and underscores (_).

ValueType

String

No

Yes

The type of the header field content.

Valid values:

  • UserDefined: A user-defined header field.

  • ReferenceHeader: A header field that references a field in the request header.

  • SystemDefined: A system-defined header field.

RewriteConfig syntax

"RewriteConfig": {
  "Path": String,
  "Query": String,
  "Host": String
}

RewriteConfig properties

Property

Type

Required

Allow Updates

Description

Constraints

Host

String

No

Yes

The destination host for the internal rewrite.

Valid values:

  • ${host} (default): This value cannot be concatenated with other strings.

  • Other values. The value must meet the following requirements:

    • The hostname must be 3 to 128 characters in length and can contain lowercase letters, digits, hyphens (-), periods (.), asterisks (*), and question marks (?).

    • The hostname must contain at least one period (.). The period cannot be the first or last character.

    • The rightmost domain label can contain only letters and wildcard characters. It cannot contain digits or hyphens (-).

    • A hyphen (-) cannot be the first or last character of a domain label.

    • An asterisk (*) or a question mark (?) can appear anywhere in a domain label.

Path

String

No

Yes

The path to rewrite.

Valid values:

  • ${path} (default): You can reference the ${host}, ${protocol}, and ${port} variables. Each variable can appear at most once. You can use these variables together or concatenate them with a supported string from the list of valid values below.

  • Other values. The value must meet the following requirements:

    • The path must be 1 to 128 characters in length.

    • It must start with a forward slash (/) and can contain letters, digits, the asterisk (*), the question mark (?), and the following special characters: $-_.+/&~@:. It cannot contain the following characters: %#;!()[]^,".

    • You can use case-sensitive English letters.

Query

String

No

Yes

The query string for the internal rewrite.

Valid values:

  • ${query} (default): You can reference the ${host}, ${protocol}, and ${port} variables. Each variable can appear at most once. You can use these variables together or concatenate them with a supported string from the list of valid values below.

  • Other values. The value must meet the following requirements:

    • The string must be 1 to 128 characters in length.

    • It cannot contain spaces or the following special characters: #[]{}\|<>&.

    • It can contain only lowercase letters.

RuleConditions syntax

"RuleConditions": [
  {
    "MethodConfig": Map,
    "PathConfig": Map,
    "Type": String,
    "QueryStringConfig": Map,
    "HostConfig": Map,
    "CookieConfig": Map,
    "HeaderConfig": Map,
    "SourceIpConfig": Map,
    "ResponseStatusCodeConfig": Map,
    "ResponseHeaderConfig": Map
  }
]

RuleConditions properties

Property

Type

Required

Updatable

Description

Constraints

Type

String

Yes

Yes

The type of the forwarding rule condition.

Valid values:

  • Host: Host

  • Path: Path

  • Header: HTTP header field

  • QueryString: Query string

  • Method: Request method

  • Cookie: Cookie

CookieConfig

Map

No

Yes

The cookie configuration.

For more information, see CookieConfig properties.

HeaderConfig

Map

No

Yes

The header field configuration.

For more information, see HeaderConfig properties.

HostConfig

Map

No

Yes

The host configuration.

For more information, see HostConfig properties.

MethodConfig

Map

No

Yes

The request method configuration.

For more information, see MethodConfig properties.

PathConfig

Map

No

Yes

The forwarding path configuration.

For more information, see PathConfig properties.

QueryStringConfig

Map

No

Yes

The query string configuration.

For more information, see QueryStringConfig properties.

SourceIpConfig

Map

No

Yes

Configuring forwarding rules.

For more information, see SourceIpConfig properties.

ResponseStatusCodeConfig

Map

No

Yes

The response status code configuration.

For more information, see ResponseStatusCodeConfig properties.

ResponseHeaderConfig

Map

No

Yes

The response header condition configuration.

For more information, see ResponseHeaderConfig properties.

ResponseStatusCodeConfig syntax

"ResponseStatusCodeConfig": {
 "Values": List
}

ResponseStatusCodeConfig properties

Property

Type

Required

Updatable

Description

Constraints

Values

List

No

Yes

The list of response status codes.

None.

ResponseHeaderConfig syntax

"ResponseHeaderConfig": {
  "Key": String,
  "Values": List
}

ResponseHeaderConfig properties

Property

Type

Required

Updatable

Description

Constraints

Key

String

No

Yes

The key of the header field.

  • The key must be 1 to 40 characters in length.

  • It can contain letters from a to z, digits, hyphens (-), and underscores (_).

  • Cookie and Host are not supported.

Values

List

No

Yes

The value of the header field.

  • The value must be 1 to 128 characters in length.

  • It can contain printable characters with ASCII values from 32 to 126, lowercase letters, and the asterisk (*) and question mark (?) wildcard characters.

  • The value cannot start or end with a space.

SourceIpConfig syntax

"SourceIpConfig": {
 "Values": List
}

SourceIpConfig properties

Property

Type

Required

Updatable

Description

Constraints

Values

List

No

Yes

One or more IP addresses or CIDR blocks.

A forwarding rule can contain up to five IP addresses.

MethodConfig syntax

"MethodConfig": {
  "Values": List
}

MethodConfig properties

Property

Type

Required

Updatable

Description

Constraints

Values

List

No

Yes

The request method.

Valid values:

  • HEAD

  • GET

  • POST

  • OPTIONS

  • PUT

  • PATCH

  • DELETE

PathConfig syntax

"PathConfig": {
  "Values": List
}

PathConfig properties

Property

Type

Required

Updatable

Description

Constraints

Values

List

No

Yes

The forwarding path.

The path must be 1 to 128 characters in length. It must start with a forward slash (/) and can contain letters, digits, the asterisk (*), the question mark (?), and the following special characters: $-_.+/&~@:. It cannot contain the following characters: %#;!()[]^,". The path is case-sensitive.

QueryStringConfig syntax

"QueryStringConfig": {
  "Values": List
}

QueryStringConfig properties

Property

Type

Required

Updatable

Description

Constraints

Values

List

No

Yes

The query string.

None

HostConfig syntax

"HostConfig": {
  "Values": List
}

HostConfig properties

Property

Type

Required

Updatable

Description

Constraints

Values

List

No

Yes

The hostname.

The value must meet the following requirements:

  • A forwarding rule condition can contain only one hostname, and the value cannot be repeated.

  • The hostname must contain at least one period (.). The period cannot be the first or last character.

  • The rightmost domain label can contain only letters and wildcard characters. It cannot contain digits or hyphens (-).

  • A hyphen (-) cannot be the first or last character of a domain label. An asterisk (*) or a question mark (?) can appear anywhere in a domain label.

CookieConfig syntax

"CookieConfig": {
  "Values": List
}

CookieConfig properties

Property

Type

Required

Updatable

Description

Constraints

Values

List

No

Yes

The list of cookie values.

None

HeaderConfig syntax

"HeaderConfig": {
  "Values": List,
  "Key": String
}

HeaderConfig properties

Property

Type

Required

Updatable

Description

Constraints

Key

String

No

Yes

The key of the header field.

The key must be 1 to 40 characters in length. It can contain lowercase letters, digits, hyphens (-), and underscores (_). Cookie and Host are not supported.

Values

List

No

Yes

The value of the header field.

The header field value must be unique within the same forwarding rule condition. The value must be 1 to 128 characters in length and can contain printable characters with ASCII values from 32 to 126, the asterisk (*), and the question mark (?). The value cannot start or end with a space.

TrafficMirrorConfig syntax

"TrafficMirrorConfig": {
 "MirrorGroupConfig": Map,
 "TargetType": String
}

TrafficMirrorConfig properties

Property

Type

Required

Updatable

Description

Constraints

MirrorGroupConfig

Map

No

Yes

The vServer group configuration.

For more information, see MirrorGroupConfig properties.

TargetType

String

No

Yes

The type of the mirroring destination.

Valid values:

  • ForwardGroupMirror: Mirrors traffic to a vServer group.

  • SlsMirror: Mirrors traffic to Simple Log Service.

MirrorGroupConfig syntax

"MirrorGroupConfig": {
 "ServerGroupTuples": List
}

MirrorGroupConfig properties

Property

Type

Required

Updatable

Description

Constraints

ServerGroupTuples

List

Yes

Yes

The list of vServer groups.

None

TrafficLimitConfig syntax

"TrafficLimitConfig": {
 "PerIpQps": Integer,
  "QPS": Integer
}

TrafficLimitConfig properties

Property

Type

Required

Updatable

Description

Constraints

PerIpQps

Integer

No

Yes

The number of queries per second (QPS) for a single IP address.

Valid values: 1 to 100000.

QPS

Integer

No

Yes

The total number of queries per second (QPS).

Valid values: 1 to 100000.

Note

If you configure both QPS and PerIpQps, the value of PerIpQps must be smaller than the value of QPS.

RemoveHeaderConfig syntax

"RemoveHeaderConfig": {
 "Key": String
}

RemoveHeaderConfig properties

Property

Type

Required

Updatable

Description

Constraints

Key

String

No

Yes

The key of the header field.

None

CorsConfig syntax

"CorsConfig": {
  "AllowMethods": List,
  "AllowHeaders": List,
  "AllowOrigin": List,
  "MaxAge": Integer,
  "AllowCredentials": String,
  "ExposeHeaders": List
}

CorsConfig properties

Property

Type

Required

Updatable

Description

Constraints

AllowMethods

List

No

Yes

The allowed HTTP methods for cross-domain requests.

The allowed HTTP methods for cross-domain access. Valid values:

  • GET

  • POST

  • PUT

  • DELETE

  • HEAD

  • OPTIONS

  • PATCH

AllowHeaders

List

No

Yes

The list of allowed headers for cross-domain requests.

Specify the * wildcard character or one or more values. Separate multiple values with commas (,). Each value can contain uppercase letters, lowercase letters, and digits. The value cannot start or end with an underscore (_) or a hyphen (-). The value can be up to 32 characters in length.

AllowOrigin

List

No

Yes

The list of allowed origins.

Specify one or more values, or only the * wildcard character.

  • Each value must start with http:// or https://, followed by a valid domain name or a top-level wildcard domain name. Example: http://*.test.abc.example.com.

  • You can specify a port. Valid ports: 1 to 65535.

AllowCredentials

String

No

Yes

Specifies whether to carry credentials.

Valid values:

  • on: Yes.

  • off: No.

ExposeHeaders

List

No

Yes

The list of headers that can be exposed.

Specify the * wildcard character or one or more values. Separate multiple values with commas (,). Each value can contain uppercase letters, lowercase letters, and digits. The value cannot start or end with an underscore (_) or a hyphen (-). The value can be up to 32 characters in length.

MaxAge

Integer

No

Yes

The maximum cache duration of a preflight request in the browser.

Unit: seconds. Valid values: -1 to 172800.

Return values

Fn::GetAtt

  • RuleId: The ID of the forwarding rule.

  • ListenerId: The ID of the listener.

Examples

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ListenerId:
    Type: String
    Description: |-
      The ID of the listener that is configured for the Application Load Balancer (ALB)
      instance.
    Default: lsn-5tl4x9oav95yeb****
Resources:
  Rule:
    Type: ALIYUN::ALB::Rule
    Properties:
      RuleActions:
        - FixedResponseConfig:
            Content: dssacav
            ContentType: text/plain
            HttpCode: '200'
          ForwardGroupConfig:
            ServerGroupTuples:
              - ServerGroupId: sgp-46ndzg2wz4v5mp****
          InsertHeaderConfig:
            Key: key
            Value: ClientSrcPort
            ValueType: SystemDefined
          Order: 1
          RedirectConfig:
            Host: ${host}
            HttpCode: '301'
            Path: /test
            Port: '10'
            Protocol: HTTP
            Query: quert
          RewriteConfig:
            Host: example.com
            Path: /tsdf
            Query: quedsa
          Type: ForwardGroup
      Priority: 10
      RuleConditions:
        - CookieConfig:
            Values:
              - Key: test
                Value: test
          HeaderConfig:
            Key: port
            Values:
              - '5006'
          HostConfig:
            Values:
              - www.example.com
          MethodConfig:
            Values:
              - PUT
          PathConfig:
            Values:
              - /test
          QueryStringConfig:
            Values:
              - Key: test
                Value: test
          Type: Host
      RuleName: MyTestRule
      ListenerId:
        Ref: ListenerId
Outputs:
  RuleId:
    Description: The ID of the forwarding rules.
    Value:
      Fn::GetAtt:
        - Rule
        - RuleId                
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ListenerId": {
      "Type": "String",
      "Description": "The ID of the listener that is configured for the Application Load Balancer (ALB)\ninstance.",
      "Default": "lsn-5tl4x9oav95yeb****"
    }
  },
  "Resources": {
    "Rule": {
      "Type": "ALIYUN::ALB::Rule",
      "Properties": {
        "RuleActions": [
          {
            "FixedResponseConfig": {
              "Content": "dssacav",
              "ContentType": "text/plain",
              "HttpCode": "200"
            },
            "ForwardGroupConfig": {
              "ServerGroupTuples": [
                {
                  "ServerGroupId": "sgp-46ndzg2wz4v5mp****"
                }
              ]
            },
            "InsertHeaderConfig": {
              "Key": "key",
              "Value": "ClientSrcPort",
              "ValueType": "SystemDefined"
            },
            "Order": 1,
            "RedirectConfig": {
              "Host": "${host}",
              "HttpCode": "301",
              "Path": "/test",
              "Port": "10",
              "Protocol": "HTTP",
              "Query": "quert"
            },
            "RewriteConfig": {
              "Host": "example.com",
              "Path": "/tsdf",
              "Query": "quedsa"
            },
            "Type": "ForwardGroup"
          }
        ],
        "Priority": 10,
        "RuleConditions": [
          {
            "CookieConfig": {
              "Values": [
                {
                  "Key": "test",
                  "Value": "test"
                }
              ]
            },
            "HeaderConfig": {
              "Key": "port",
              "Values": [
                "5006"
              ]
            },
            "HostConfig": {
              "Values": [
                "www.example.com"
              ]
            },
            "MethodConfig": {
              "Values": [
                "PUT"
              ]
            },
            "PathConfig": {
              "Values": [
                "/test"
              ]
            },
            "QueryStringConfig": {
              "Values": [
                {
                  "Key": "test",
                  "Value": "test"
                }
              ]
            },
            "Type": "Host"
          }
        ],
        "RuleName": "MyTestRule",
        "ListenerId": {
          "Ref": "ListenerId"
        }
      }
    }
  },
  "Outputs": {
    "RuleId": {
      "Description": "The ID of the forwarding rules.",
      "Value": {
        "Fn::GetAtt": [
          "Rule",
          "RuleId"
        ]
      }
    }
  }
}