ALIYUN::SAE::ApplicationScalingRule类型用于创建应用弹性伸缩策略。
语法
{
  "Type": "ALIYUN::SAE::ApplicationScalingRule",
  "Properties": {
    "AppId": String,
    "ScalingRuleName": String,
    "ScalingRuleType": String,
    "MinReadyInstances": Integer,
    "MinReadyInstanceRatio": Integer,
    "ScalingRuleMetric": Map,
    "ScalingRuleTimer": Map,
    "ScalingRuleEnable": Boolean
  }
}属性
| 属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 | 
| AppId | String | 是 | 否 | 应用 ID。 | 无 | 
| ScalingRuleName | String | 是 | 否 | 自定义的弹性伸缩策略名。 | 应用内,策略名称不可重复,必须以小写字母开头,仅可包含小写字母、数字及短划线(-),不超过 32 个字符。 | 
| ScalingRuleType | String | 是 | 否 | 弹性伸缩策略类型。 | 取值: 
 说明  如果选择定时弹性,ScalingRuleTimer 字段为必填项。 如果选择监控指标弹性,ScalingRuleMetric 字段为必填项。 如果选择混合弹性,ScalingRuleMetric 字段为必填项,ScalingRuleTimer 字段和 ScalingRuleMetric 字段也可以按需同时填写。 | 
| MinReadyInstances | Integer | 否 | 否 | 最小存活实例数。 | 取值说明如下: 
 说明  每次滚动部署最小存活的实例数建议≥1,保证业务不中断。 | 
| MinReadyInstanceRatio | Integer | 否 | 否 | 最小存活实例数百分比。 | 取值说明如下: 
 说明  当MinReadyInstances和MinReadyInstanceRatio同时传递时,且MinReadyInstanceRatio的取值非**-1**时,以MinReadyInstanceRatio参数为准。假设MinReadyInstances取值为5,MinReadyInstanceRatio取值为50,则会用50来计算最小存活实例数。 | 
| ScalingRuleMetric | Map | 否 | 是 | 监控指标弹性策略的配置。 | 当您选择监控指标弹性策略设置时,该参数必选。 参数说明如下: 
 说明  您可以选择设置一个或多个监控指标。当设置多个监控指标时,只要任何一个指标大于或者等于目标值,则应用进行扩容,扩容后实例数不高于应用最大实例数;如果所有指标均小于目标值,则应用进行缩容,缩容后实例数不低于应用最小实例数。 | 
| ScalingRuleTimer | Map | 否 | 是 | 定时弹性策略的配置。 | 当您选择定时弹性策略或使用 SDK 设置时,该参数必选。 参数说明如下: 
 说明  每次滚动部署最小存活的实例数建议大于等于1,保证业务不中断。如果设置为0,应用在升级过程中将会中断业务。 | 
| ScalingRuleEnable | Boolean | 否 | 否 | 是否启用弹性伸缩策略。 | 取值说明如下: 
 | 
ScalingRuleMetric语法
"ScalingRuleMetric": {
  "Metrics": List,
  "MinReplicas": Integer,
  "MaxReplicas": Integer,
  "ScaleDownRules": Map,
  "ScaleUpRules": Map
}ScalingRuleMetric属性
| 属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 | 
| Metrics | List | 是 | 否 | 监控指标弹性伸缩列表。 | 无 | 
| MinReplicas | Integer | 是 | 否 | 最小实例数。 | 无 | 
| MaxReplicas | Integer | 是 | 否 | 最大实例数。 | 无 | 
| ScaleDownRules | Map | 否 | 否 | 应用缩容规则。 | 无 | 
| ScaleUpRules | Map | 否 | 否 | 应用扩容规则。 | 无 | 
Metrics语法
"Metrics": [
  {
    "SlbId": String,
    "MetricType": String,
    "Vport": String,
    "SlbLogstore": String,
    "SlbProject": String,
    "MetricTargetAverageUtilization": Integer
  }
]Metrics属性
| 属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 | 
| MetricType | String | 是 | 否 | 监控指标触发条件。 | 取值说明如下: 
 | 
| MetricTargetAverageUtilization | Integer | 是 | 否 | 监控指标的目标值。 | 
 | 
| SlbId | String | 否 | 否 | SLB 实例 ID。 | 无 | 
| SlbLogstore | String | 否 | 否 | 日志服务 Logstore。 | 无 | 
| SlbProject | String | 否 | 否 | 日志服务 Project。 | 无 | 
| Vport | String | 否 | 否 | SLB 监听端口,支持 HTTP 协议和 HTTPS 协议。 | 无 | 
ScaleDownRules语法
"ScaleDownRules": {
  "Step": String,
  "StabilizationWindowSeconds": Integer,
  "Disabled": Boolean
}ScaleDownRules属性
| 属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 | 
| Step | String | 是 | 否 | 弹性缩容步长。 | 单位时间内最多缩容的实例数。 | 
| Disabled | Boolean | 否 | 否 | 是否禁止缩容。 | 开启后将永远不会缩容该应用的实例,能有效防止在流量高峰期缩容造成业务风险。 取值: 
 | 
| StabilizationWindowSeconds | Integer | 否 | 否 | 缩容的冷却时间。 | 取值范围[0, 3600],单位为秒。默认为 0 秒。 | 
ScaleUpRules语法
"ScaleUpRules": {
  "Step": String,
  "StabilizationWindowSeconds": Integer,
  "Disabled": Boolean
}ScaleUpRules属性
| 属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 | 
| Step | String | 是 | 否 | 弹性扩容步长。 | 单位时间内最多扩容的实例数。 | 
| Disabled | Boolean | 否 | 否 | 是否禁止扩容。 | 开启后将永远不会扩容该应用的实例,能有效防止在流量高峰期扩容造成业务风险。 | 
| StabilizationWindowSeconds | Integer | 否 | 否 | 扩容的冷却时间。 | 取值范围[0, 3600],单位为秒。默认为 0 秒。 | 
ScalingRuleTimer语法
"ScalingRuleTimer": {
  "Schedules": List,
  "Period": String,
  "EndDate": String,
  "BeginDate": String
}ScalingRuleTimer属性
| 属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 | 
| Period | String | 是 | 否 | 执行定时弹性伸缩策略的周期。 | 取值说明如下: 
 | 
| Schedules | List | 是 | 否 | 单天内触发时间点。 | 无。 | 
| BeginDate | String | 否 | 否 | 定时弹性伸缩策略的短期起始日期。 | 
 | 
| EndDate | String | 否 | 否 | 定时弹性伸缩策略的短期结束日期。 | 
 | 
Schedules语法
"Schedules": [
  {
    "TargetReplicas": Integer,
    "AtTime": String
  }
]Schedules属性
| 属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 | 
| AtTime | String | 是 | 否 | 触发时间点。 | 无 | 
| TargetReplicas | Integer | 是 | 否 | 该参数可以指定应用的实例数,也可以是每次部署最小存活的实例数。 | 取值范围[1,50]。 | 
返回值
Fn::GetAtt
ScalingRuleName:自定义的弹性伸缩策略名。
示例
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ScalingRuleName:
    Type: String
    Description:
      en: The name of the auto scaling policy. The name must start with a lowercase letter, and can contain lowercase letters, digits, and hyphens (-).The name must be 1 to 32 characters in length.
    AllowedPattern: ^[a-z][a-z0-9-]{0,31}$
    Required: true
  AppId:
    Type: String
    Description:
      en: The ID of the application.
    Required: true
  ScalingRuleType:
    Type: String
    Description:
      en: 'The type of the auto scaling policy. Valid values: timer: Timed scaling. metric: Custom metric scaling.mix: mix scaling'
    AllowedValues:
      - timing
      - metric
      - mix
    Required: true
Resources:
  ApplicationScalingRule:
    Type: ALIYUN::SAE::ApplicationScalingRule
    Properties:
      ScalingRuleName:
        Ref: ScalingRuleName
      AppId:
        Ref: AppId
      ScalingRuleType:
        Ref: ScalingRuleType
Outputs:
  ScalingRuleName:
    Description: The name of the scaling rule.
    Value:
      Fn::GetAtt:
        - ApplicationScalingRule
        - ScalingRuleName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ScalingRuleName": {
      "Type": "String",
      "Description": {
        "en": "The name of the auto scaling policy. The name must start with a lowercase letter, and can contain lowercase letters, digits, and hyphens (-).The name must be 1 to 32 characters in length."
      },
      "AllowedPattern": "^[a-z][a-z0-9-]{0,31}$",
      "Required": true
    },
    "AppId": {
      "Type": "String",
      "Description": {
        "en": "The ID of the application."
      },
      "Required": true
    },
    "ScalingRuleType": {
      "Type": "String",
      "Description": {
        "en": "The type of the auto scaling policy. Valid values: timer: Timed scaling. metric: Custom metric scaling.mix: mix scaling"
      },
      "AllowedValues": [
        "timing",
        "metric",
        "mix"
      ],
      "Required": true
    }
  },
  "Resources": {
    "ApplicationScalingRule": {
      "Type": "ALIYUN::SAE::ApplicationScalingRule",
      "Properties": {
        "ScalingRuleName": {
          "Ref": "ScalingRuleName"
        },
        "AppId": {
          "Ref": "AppId"
        },
        "ScalingRuleType": {
          "Ref": "ScalingRuleType"
        }
      }
    }
  },
  "Outputs": {
    "ScalingRuleName": {
      "Description": "The name of the scaling rule.",
      "Value": {
        "Fn::GetAtt": [
          "ApplicationScalingRule",
          "ScalingRuleName"
        ]
      }
    }
  }
}