AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

AWS::ApplicationAutoScaling::ScalingPolicy

AWS::ApplicationAutoScaling::ScalingPolicy 资源定义 Application Auto Scaling 扩展策略,Application Auto Scaling 使用该策略调整您的应用程序资源。

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

JSON

{ "Type" : "AWS::ApplicationAutoScaling::ScalingPolicy", "Properties" : { "PolicyName" : String, "PolicyType" : String, "ResourceId" : String, "ScalableDimension" : String, "ScalingTargetId" : String, "ServiceNamespace" : String, "StepScalingPolicyConfiguration" : StepScalingPolicyConfiguration, "TargetTrackingScalingPolicyConfiguration" : TargetTrackingScalingPolicyConfiguration } }

属性

PolicyName

扩展策略的名称。

Required: Yes

Type: String

更新要求替换

PolicyType

Application Auto Scaling 策略类型。

注意

对于 DynamoDB,仅支持 TargetTrackingScaling。对于任何其他服务,仅支持 StepScaling

Required: Yes

Type: String

更新要求无需中断

ResourceId

此扩展策略应用于的可扩展目标的唯一资源标识符。有关更多信息,请参阅 Application Auto Scaling API 参考 中的 PutScalingPolicy 操作的 ResourceId 参数。

Required: Conditional。您必须指定 ScalingTargetId 属性或 ResourceIdScalableDimensionServiceNamespace 属性。如果您指定了 ResourceIdScalableDimensionServiceNamespace 属性,请勿指定 ScalingTargetId 属性。

Type: String

更新要求替换

ScalableDimension

此扩展策略应用于的可扩展目标的可扩展维度。可扩展维度包含服务命名空间、资源类型和扩展属性,例如 Amazon ECS 服务的所需任务计数的 ecs:service:DesiredCount。

Required: Conditional。您必须指定 ScalingTargetId 属性或 ResourceIdScalableDimensionServiceNamespace 属性。如果您指定了 ResourceIdScalableDimensionServiceNamespace 属性,请勿指定 ScalingTargetId 属性。

Type: String

更新要求替换

ServiceNamespace

此扩展策略应用于的可扩展目标的 AWS 服务命名空间。有关服务命名空间的列表,请参阅 AWS General Reference 中的 AWS 服务命名空间

Required: Conditional。您必须指定 ScalingTargetId 属性或 ResourceIdScalableDimensionServiceNamespace 属性。如果您指定了 ResourceIdScalableDimensionServiceNamespace 属性,请勿指定 ScalingTargetId 属性。

Type: String

更新要求替换

ScalingTargetId

Application Auto Scaling 可扩展目标的 AWS CloudFormation 生成的 ID。有关此 ID 的更多信息,请参阅 AWS::ApplicationAutoScaling::ScalableTarget 资源的“返回值”部分。

Required: Conditional。您必须指定 ScalingTargetId 属性或 ResourceIdScalableDimensionServiceNamespace 属性。如果您指定了此属性,请勿指定 ResourceIdScalableDimensionServiceNamespace 属性。

Type: String

更新要求替换

StepScalingPolicyConfiguration

用于配置 Application Auto Scaling 增加或减少资源的时间以及增加或减少的数量的步进策略。

Required: No

Type: Application Auto Scaling ScalingPolicy StepScalingPolicyConfiguration

更新要求无需中断

TargetTrackingScalingPolicyConfiguration

配置一个目标跟踪扩展策略。

如果创建的是新策略且策略类型为 TargetTrackingScaling,则该参数是必需的。

Required: No

Type: Application Auto Scaling ScalingPolicy TargetTrackingScalingPolicyConfiguration

更新要求无需中断

返回值

Ref

当向 Ref 内部函数提供此资源的逻辑 ID 时,Ref 将返回 Application Auto Scaling 扩展策略的 Amazon 资源名称 (ARN),如 arn:aws-cn:autoscaling:us-east-2:123456789012:scalingPolicy:12ab3c4d-56789-0ef1-2345-6ghi7jk8lm90:resource/ecs/service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH:policyName/MyStepPolicy

有关使用 Ref 功能的更多信息,请参阅参考

示例

使用步进策略配置的 Application Auto Scaling 扩展策略

以下示例将使用步进策略配置来创建 Application Auto Scaling 扩展策略。当关联警报触发时,该策略将可扩展目标的预期数量增加 200%,并将冷却时间设置为 60 秒。

JSON

"scalingPolicy" : { "Type" : "AWS::ApplicationAutoScaling::ScalingPolicy", "Properties" : { "PolicyName" : "AStepPolicy", "PolicyType" : "StepScaling", "ScalingTargetId" : {"Ref": "scalableTarget"}, "StepScalingPolicyConfiguration" : { "AdjustmentType" : "PercentChangeInCapacity", "Cooldown" : 60, "MetricAggregationType" : "Average", "StepAdjustments" : [{ "MetricIntervalLowerBound" : 0, "ScalingAdjustment" : 200 }] } } }

YAML

scalingPolicy: Type: 'AWS::ApplicationAutoScaling::ScalingPolicy' Properties: PolicyName: AStepPolicy PolicyType: StepScaling ScalingTargetId: Ref: scalableTarget StepScalingPolicyConfiguration: AdjustmentType: PercentChangeInCapacity Cooldown: 60 MetricAggregationType: Average StepAdjustments: - MetricIntervalLowerBound: 0 ScalingAdjustment: 200

使用 Amazon DynamoDB 表的 Application Auto Scaling 扩展策略

此示例为 AWS::DynamoDB::Table 资源设置 Application Auto Scaling。此模板定义扩展表的 WriteCapacityUnits 吞吐量的 TargetTrackingScaling 扩展策略。

JSON

{ "Resources": { "DDBTable": { "Type": "AWS::DynamoDB::Table", "Properties": { "AttributeDefinitions": [ { "AttributeName": "ArtistId", "AttributeType": "S" }, { "AttributeName": "Concert", "AttributeType": "S" }, { "AttributeName": "TicketSales", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "ArtistId", "KeyType": "HASH" }, { "AttributeName": "Concert", "KeyType": "RANGE" } ], "GlobalSecondaryIndexes": [ { "IndexName": "GSI", "KeySchema": [ { "AttributeName": "TicketSales", "KeyType": "HASH" } ], "Projection": { "ProjectionType": "KEYS_ONLY" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 } } ], "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 } } }, "WriteCapacityScalableTarget": { "Type": "AWS::ApplicationAutoScaling::ScalableTarget", "Properties": { "MaxCapacity": 15, "MinCapacity": 5, "ResourceId": { "Fn::Join": [ "/", [ "table", { "Ref": "DDBTable" } ] ] }, "RoleARN": { "Fn::GetAtt": ["ScalingRole", "Arn"] }, "ScalableDimension": "dynamodb:table:WriteCapacityUnits", "ServiceNamespace": "dynamodb" } }, "ScalingRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "application-autoscaling.amazonaws.com" ] }, "Action": [ "sts:AssumeRole" ] } ] }, "Path": "/", "Policies": [ { "PolicyName": "root", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "dynamodb:DescribeTable", "dynamodb:UpdateTable", "cloudwatch:PutMetricAlarm", "cloudwatch:DescribeAlarms", "cloudwatch:GetMetricStatistics", "cloudwatch:SetAlarmState", "cloudwatch:DeleteAlarms" ], "Resource": "*" } ] } } ] } }, "WriteScalingPolicy": { "Type": "AWS::ApplicationAutoScaling::ScalingPolicy", "Properties": { "PolicyName": "WriteAutoScalingPolicy", "PolicyType": "TargetTrackingScaling", "ScalingTargetId": { "Ref": "WriteCapacityScalableTarget" }, "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 50.0, "ScaleInCooldown": 60, "ScaleOutCooldown": 60, "PredefinedMetricSpecification": { "PredefinedMetricType": "DynamoDBWriteCapacityUtilization" } } } } } }

YAML

Resources: DDBTable: Type: "AWS::DynamoDB::Table" Properties: AttributeDefinitions: - AttributeName: "ArtistId" AttributeType: "S" - AttributeName: "Concert" AttributeType: "S" - AttributeName: "TicketSales" AttributeType: "S" KeySchema: - AttributeName: "ArtistId" KeyType: "HASH" - AttributeName: "Concert" KeyType: "RANGE" GlobalSecondaryIndexes: - IndexName: "GSI" KeySchema: - AttributeName: "TicketSales" KeyType: "HASH" Projection: ProjectionType: "KEYS_ONLY" ProvisionedThroughput: ReadCapacityUnits: 5 WriteCapacityUnits: 5 ProvisionedThroughput: ReadCapacityUnits: 5 WriteCapacityUnits: 5 WriteCapacityScalableTarget: Type: "AWS::ApplicationAutoScaling::ScalableTarget" Properties: MaxCapacity: 15 MinCapacity: 5 ResourceId: !Join - / - - table - !Ref DDBTable RoleARN: !GetAtt ScalingRole.Arn ScalableDimension: dynamodb:table:WriteCapacityUnits ServiceNamespace: dynamodb ScalingRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Principal: Service: - application-autoscaling.amazonaws.com Action: - "sts:AssumeRole" Path: "/" Policies: - PolicyName: "root" PolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Action: - "dynamodb:DescribeTable" - "dynamodb:UpdateTable" - "cloudwatch:PutMetricAlarm" - "cloudwatch:DescribeAlarms" - "cloudwatch:GetMetricStatistics" - "cloudwatch:SetAlarmState" - "cloudwatch:DeleteAlarms" Resource: "*" WriteScalingPolicy: Type: "AWS::ApplicationAutoScaling::ScalingPolicy" Properties: PolicyName: WriteAutoScalingPolicy PolicyType: TargetTrackingScaling ScalingTargetId: !Ref WriteCapacityScalableTarget TargetTrackingScalingPolicyConfiguration: TargetValue: 50.0 ScaleInCooldown: 60 ScaleOutCooldown: 60 PredefinedMetricSpecification: PredefinedMetricType: DynamoDBWriteCapacityUtilization

本页内容: