ALIYUN::Config::Rule is used to create a forwarding rule.

Syntax

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

Properties

PropertyTypeRequiredEditableDescriptionConstraint
RuleActionsListYesYesThe actions that are performed based on the forwarding rule. For more information, see RuleActions properties.
PriorityIntegerYesYesThe priority of the forwarding rule. Valid values: 1 to 10000. A smaller value indicates a higher priority.
Note The priority of each forwarding rule that you specify for a listener must be unique.
RuleConditionsListYesYesThe conditions for the forwarding rule. For more information, see RuleConditions properties.
DirectionStringNoNoThe direction to which the forwarding rule is applied. Valid values:
  • Request: inbound
  • Response: outbound
RuleNameStringYesYesThe name of the forwarding rule. The name must be 2 to 128 characters in length, and can contain letters, digits, periods (.), underscores (_), and hyphens (-). The name must start with a letter.
ListenerIdStringYesNoThe ID of the listener that is added to the Application Load Balancer (ALB) instance. None.

RuleActions syntax

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

RuleActions properties

PropertyTypeRequiredEditableDescriptionConstraint
OrderIntegerYesYesThe execution priority of the actions. Valid values: 1 to 50000. A smaller value indicates a higher priority.
Note The execution priority of each action must be unique.
FixedResponseConfigMapNoYesThe configuration of the fixed response. For more information, see FixedResponseConfig properties.
TypeStringYesYesThe type of the action. Valid values:
  • ForwardGroup: forwards a request to multiple vServer groups.
  • Redirect: redirects a request.
  • FixedResponse: returns a fixed response.
  • Rewrite: rewrites a request.
  • InsertHeader: adds a header to a request.
RedirectConfigMapNoYesThe configuration of the redirect action. For more information, see RedirectConfig properties.
ForwardGroupConfigMapNoYesThe configuration of the vServer group. For more information, see ForwardGroupConfig properties.
InsertHeaderConfigMapNoYesThe configuration of the header that you want to add to a request. For more information, see InsertHeaderConfig properties.
RewriteConfigMapNoYesThe configuration of the rewrite action. For more information, see RewriteConfig properties.
TrafficMirrorConfigMapNoYesThe configuration of the traffic mirroring feature. For more information, see TrafficMirrorConfig properties.
TrafficLimitConfigMapNoYesThe configuration of the traffic throttling feature. For more information, see TrafficLimitConfig properties.
RemoveHeaderConfigMapNoYesThe configuration of the header that you want to remove from the request. For more information, see RemoveHeaderConfig properties.

FixedResponseConfig syntax

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

FixedResponseConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
HttpCodeStringNoYesThe HTTP status code to return. Valid values: HTTP_2xx, HTTP_4xx, and HTTP_5xx. x is a digit.
ContentTypeStringNoYesThe format of the fixed response. Valid values:
  • text/plain
  • text/css
  • text/html
  • application/javascript
  • application/json
ContentStringNoYesThe content of the fixed response. The content can be up to 1 KB in size and can contain only ASCII characters.

RedirectConfig syntax

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

RedirectConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
PathStringNoYesThe path to which requests are redirected. Default value: ${path}. Valid values:
  • ${path}. You can reference ${host}, ${protocol}, and ${port} in the value. You can reference each variable only once in a path. You can specify all the preceding variables in a path at a time. You can also combine the variables with a custom value.
  • A custom value. Make sure that the custom value meets the following requirements:
    • The value must be 1 to 128 characters in length.
    • The value must start with a forward slash (/). The value can contain letters, digits, and the following special characters: $ - _ .+ / & ~ @ : ∗ ?. The value cannot contain the following special characters: % # ; ! () [] ^ , ".
    • The value is case-sensitive.
HttpCodeIntegerNoYesThe HTTP status code. Valid values:
  • 301
  • 302
  • 303
  • 307
  • 308
QueryStringNoYesThe query string of the URL to which requests are redirected. Default value: ${query}. Valid values:
  • ${query}. You can reference ${host}, ${protocol}, and ${port} in the value. You can reference each variable only once in a query string. You can specify all the preceding variables in a query string at a time. You can also combine the variables with a custom value.
  • A custom value. Make sure that the custom value meets the following requirements:
    • The value must be 1 to 128 characters in length.
    • The value cannot contain a space and the following special characters: # [] {} \ | <> &.
    • The value must be lowercase letters.
PortStringNoYesThe port to which requests are redirected. Default value: ${port}. Valid values:
  • ${port}. You cannot combine ${port} with a custom value.
  • A custom value. Valid values: 1 to 63335.
HostStringNoYesThe URL of the host to which requests are redirected. Default value: ${host}. Valid values:
  • ${host}. You cannot combine ${host} with a custom value.
  • A custom value. Make sure that the custom value meets 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 (.) but cannot start or end with a period (.).
    • The rightmost domain label can contain only letters and wildcard characters but cannot contain digits or hyphens (-).
    • A domain label cannot start or end with a hyphen (-).
    • You can place asterisks (∗) and question marks (?) anywhere in a domain label.
ProtocolStringNoYesThe redirect protocol. Default value: ${protocol}. Valid values:
  • ${protocol}. You cannot combine ${protocol} with other types of characters.
  • HTTP
  • HTTPS
    Note HTTPS listeners support only HTTPS to HTTPS redirects.

ForwardGroupConfig syntax

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

ForwardGroupConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
ServerGroupTuplesListNoYesThe vServer groups to which requests are forwarded. For more information, see ServerGroupTuples property.
ServerGroupStickySessionMapNoYesThe configuration of session persistence. For more information, see ServerGroupStickySession properties.

ServerGroupStickySession syntax

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

ServerGroupStickySession properties

PropertyTypeRequiredEditableDescriptionConstraint
EnabledBooleanNoYesSpecifies whether to enable session persistence. Default value: false. Valid values:
  • true
  • false
TimeoutIntegerNoYesThe timeout period. Unit: seconds. Valid values: 1 to 86400.

ServerGroupTuples syntax

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

ServerGroupTuples property

PropertyTypeRequiredEditableDescriptionConstraint
ServerGroupIdStringYes YesThe ID of the vServer group to which requests are forwarded. None.

InsertHeaderConfig syntax

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

InsertHeaderConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
ValueTypeStringNoYesThe type of the header. Valid values:
  • UserDefined: a custom header that you specify
  • ReferenceHeader: a header that you reference from one of the request headers
  • SystemDefined: a header that is defined by the system
ValueStringNoYesThe value of the header. Valid values:
  • If you set the ValueType property to SystemDefined, you can set the Value property to one of the following values:
    • ClientSrcPort: the port of the client.
    • ClientSrcIp: the IP address of the client.
    • Protocol: the request protocol of the client. You can set the protocol to HTTP or HTTPS.
    • SLBId: the ID of the ALB instance.
    • SLBPort: the listening port of the ALB instance.
  • If you set the ValueType property to ReferenceHeader, you must take note of the following items:

    You can reference one of the request headers. The header must be 1 to 128 characters in length, and can contain lowercase letters, digits, hyphens (-), and underscores (_).

KeyStringNoYesThe name of the header. The name must be 1 to 40 characters in length, and can contain letters, digits, underscores (_), and hyphens (-). The header name that you specify for the InsertHeaderConfig property must be unique.
Note The name is not case-sensitive. You cannot set a header name to one of the following values: 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, and authority.

RewriteConfig syntax

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

RewriteConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
PathStringNoYesThe path to which requests are redirected. Default value: ${path}. Valid values:
  • ${path}. You can reference ${host}, ${protocol}, and ${port} in the value. You can reference each variable only once in a path. You can specify all the preceding variables in a path at a time. You can also combine the variables with a custom value.
  • A custom value. Make sure that the custom value meets the following requirements:
    • The value must be 1 to 128 characters in length.
    • The value must start with a forward slash (/). The value can contain letters, digits, and the following special characters: $ - _ .+ / & ~ @ : ∗ ?. The value cannot contain the following special characters: % # ; ! () [] ^ , ″".
    • The value is case-sensitive.
QueryStringNoYesThe query string of the URL to which requests are forwarded. Default value: ${query}. Valid values:
  • ${query}. You can reference ${host}, ${protocol}, and ${port} in the value. You can reference each variable only once in a query string. You can specify all the preceding variables in a query string at a time. You can also combine the variables with a custom value.
  • A custom value. Make sure that the custom value meets the following requirements:
    • The value must be 1 to 128 characters in length.
    • The value cannot contain a space and the following special characters: # [] {} \ | <> &.
    • The value must be lowercase letters.
HostStringNoYesThe URL of the host to which requests are redirected. Default value: ${host}. Valid values:
  • ${host}. You cannot combine ${host} with a custom value.
  • A custom value. Make sure that the custom value meets 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 (.) but cannot start or end with a period (.).
    • The rightmost domain label can contain only letters and wildcard characters but cannot contain digits or hyphens (-).
    • A domain label cannot start or end with a hyphen (-).
    • You can specify asterisks (∗) and question marks (?) anywhere in a domain label.

RuleConditions syntax

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

RuleConditions properties

PropertyTypeRequiredEditableDescriptionConstraint
MethodConfigMapNoYesThe configuration of the request method. For more information, see MethodConfig property.
PathConfigMapNoYesThe configuration of the path to which requests are redirected. For more information, see PathConfig property.
TypeStringYesYesThe type of the forwarding rule. Valid values:
  • Host: forwards requests based on hosts.
  • Path: forwards requests based on paths.
  • Header: forwards requests based on HTTP headers.
  • QueryString: forwards requests based on query strings.
  • Method: forwards requests based on request methods.
  • Cookie: forwards requests based on cookies.
ResponseHeaderConfigMapNoNoThe configuration of the HTTP response header. For more information, see ResponseHeaderConfig properties.
QueryStringConfigMapNoYesThe configuration of the query string. For more information, see QueryStringConfig property.
HostConfigMapNoYesThe configuration of the host. For more information, see HostConfig property.
CookieConfigMapNoYesThe configuration of the cookie. For more information, see CookieConfig property.
HeaderConfigMapNoYesThe configuration of the header. For more information, see HeaderConfig properties.
SourceIpConfigMapNoYesThe configuration of the source IP address for the forwarding rule. For more information, see SourceIpConfig property.

SourceIpConfig syntax

"SourceIpConfig": {
  "Values": List
}

SourceIpConfig property

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesOne or more IP addresses or CIDR blocks that you want to add in a forwarding rule. You can add up to five IP addresses or CIDR blocks in a forwarding rule.

MethodConfig syntax

"MethodConfig": {
  "Values": List
}

MethodConfig property

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesThe request method. Valid values:
  • HEAD
  • GET
  • POST
  • OPTIONS
  • PUT
  • PATCH
  • DELETE

PathConfig syntax

"PathConfig": {
  "Values": List
}

PathConfig property

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesThe path to which requests are redirected. The path must be 1 to 128 characters in length, and can contain letters, digits, asterisks (∗), question marks (?), and the following special characters: $ - _ . + / & ~ @ :. The path cannot contain the following special characters: “ % # ; ! () [] ^ , ”. The path must start with a forward slash (/). The path is case-sensitive.

ResponseHeaderConfig syntax

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

ResponseHeaderConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesThe value of the header. None.
KeyStringNoYesThe name of the header. The name must be 1 to 40 characters in length, and can contain letters, digits, hyphens (-), and underscores (_). You cannot configure cookies or hosts.

QueryStringConfig syntax

"QueryStringConfig": {
  "Values": List
}

QueryStringConfig property

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesThe query strings. None.

HostConfig syntax

"HostConfig": {
  "Values": List
}

HostConfig property

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesThe hostname. Make sure that the hostname meets the following requirements:
  • A forwarding rule can contain only one hostname. The hostname that you specify for a forwarding rule must be unique.
  • The hostname must contain at least one period (.) but cannot start or end with a period (.).
  • The rightmost domain label can contain only letters and wildcard characters but cannot contain digits or hyphens (-).
  • A domain label cannot start or end with a hyphen (-). You can specify asterisks (∗) and question marks (?) anywhere in a domain label.

CookieConfig syntax

"CookieConfig": {
  "Values": List
}

CookieConfig property

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesThe cookie values. None.

HeaderConfig syntax

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

HeaderConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
ValuesListNoYesThe header values. The value that you specify for a header in a forwarding rule must be unique. The value must be 1 to 128 characters in length, and can contain asterisks (∗), question marks (?), and printable characters of the ASCII code from 32 and to 126 (ch >= 32 && ch < 127). The value cannot start or end with a space.
KeyStringNoYesThe header name. The name must be 1 to 40 characters in length, and can contain lowercase letters, digits, hyphens (-), and underscores (_). You cannot configure cookies or hosts.

TrafficMirrorConfig syntax

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

TrafficMirrorConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
MirrorGroupConfigMapYesYesThe configuration of the vServer group. For more information, see MirrorGroupConfig property.
TargetTypeStringYesYesThe type of destination to which network traffic is mirrored. Valid values:
  • ForwardGroupMirror: a vServer group
  • SlsMirror: Log Service

MirrorGroupConfig syntax

"MirrorGroupConfig": {
  "ServerGroupTuples": List
}

MirrorGroupConfig property

PropertyTypeRequiredEditableDescriptionConstraint
ServerGroupTuplesListYesYesThe vServer groups. None.

TrafficLimitConfig syntax

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

TrafficLimitConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
PerIpQpsIntegerNoYesThe queries per second (QPS). Valid values: 1 to 100000.
QPSIntegerYesYesThe QPS per IP address. Valid values: 1 to 100000.
Note If both the QPS and PerIpQps properties are specified, make sure that the value of the QPS property is smaller than the value of the PerIpQps property.

RemoveHeaderConfig syntax

"RemoveHeaderConfig": {
  "Key": String
}

RemoveHeaderConfig properties

PropertyTypeRequiredEditableDescriptionConstraint
KeyStringNoYesThe name of the header. None.

Return values

Fn::GetAtt

RuleId: the ID of the forwarding rule.

Examples

  • YAMLformat

    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                
  • JSONformat

    {
      "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"
            ]
          }
        }
      }
    }