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

AWS::ApplicationAutoScaling::ScalableTarget

AWS::ApplicationAutoScaling::ScalableTarget 资源指定 Application Auto Scaling 可向上扩展或向下扩展的资源。有关更多信息,请参阅 Application Auto Scaling API 参考 中的 RegisterScalableTarget 操作。

语法

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

JSON

{ "Type" : "AWS::ApplicationAutoScaling::ScalableTarget", "Properties" : { "MaxCapacity" : Integer, "MinCapacity" : Integer, "ResourceId" : String, "RoleARN" : String, "ScalableDimension" : String, "ServiceNamespace" : String } }

YAML

Type: "AWS::ApplicationAutoScaling::ScalableTarget" Properties: MaxCapacity: Integer MinCapacity: Integer ResourceId: String RoleARN: String ScalableDimension: String ServiceNamespace: String

属性

MaxCapacity

Application Auto Scaling 可在扩展活动期间用来扩展目标的最大值。

Required: Yes

Type: Integer

更新要求无需中断

MinCapacity

Application Auto Scaling 可在扩展活动期间用来扩展目标的最小值。

Required: Yes

Type: Integer

更新要求无需中断

ResourceId

要与此可扩展目标关联的资源标识符。该字符串由资源类型和唯一标识符组成。有关更多信息,请参阅 Application Auto Scaling API 参考 中的 RegisterScalableTarget 操作的 ResourceId 参数,或查看ScalableTarget示例

Required: Yes

Type: String

更新要求替换

RoleARN

允许 Application Auto Scaling 修改您的可扩展目标的 AWS Identity and Access Management (IAM) 角色的 Amazon 资源名称 (ARN)。

Required: Yes

Type: String

更新要求无需中断

ScalableDimension

与可扩展目标关联的可扩展维度。指定服务命名空间、资源类型和扩展属性,例如 Amazon Elastic Container Service 服务的所需任务计数的 ecs:service:DesiredCount。对于有效值,请参阅 Application Auto Scaling API 参考 中的 ScalingPolicy 数据类型的 ScalableDimension 内容。

Required: Yes

Type: String

更新要求替换

ServiceNamespace

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

Required: Yes

Type: String

更新要求替换

返回值

Ref

当向 Ref 内部函数提供此资源的逻辑 ID 时,Ref 将返回此资源的 AWS CloudFormation 生成的 ID,如 service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH|ecs:service:DesiredCount|ecs

AWS CloudFormation 使用以下格式生成 ID:service/resource_ID|scalable_dimension|service_namespace

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

示例

任务数

以下示例将为 Amazon Elastic Container Service 服务创建可扩展目标。Application Auto Scaling 将扩展任务的数量,最少 1 个任务,最多 2 个任务。

JSON

"scalableTarget" : { "Type" : "AWS::ApplicationAutoScaling::ScalableTarget", "Properties" : { "MaxCapacity" : 2, "MinCapacity" : 1, "ResourceId" : "service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH", "RoleARN" : {"Fn::GetAtt" : ["ApplicationAutoScalingRole", "Arn"] }, "ScalableDimension" : "ecs:service:DesiredCount", "ServiceNamespace" : "ecs" } }

YAML

scalableTarget: Type: AWS::ApplicationAutoScaling::ScalableTarget Properties: MaxCapacity: 2 MinCapacity: 1 ResourceId: service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH RoleARN: !GetAtt [ ApplicationAutoScalingRole, Arn ] ScalableDimension: ecs:service:DesiredCount ServiceNamespace: ecs

使用 Fn::JoinRef 构建 ResourceId

下面的示例使用 Fn::JoinRef 内部函数来构造扩展目标的 ResourceId 属性。

JSON

"SpotFleetScalingTarget": { "Type": "AWS::ApplicationAutoScaling::ScalableTarget", "Properties": { "MaxCapacity": 2, "MinCapacity": 1, "ResourceId": { "Fn::Join": [ "/", [ "spot-fleet-request", { "Ref": "ECSSpotFleet" } ] ] }, "RoleARN": { "Fn::GetAtt": [ "AutoScalingRole", "Arn" ] }, "ScalableDimension": "ec2:spot-fleet-request:TargetCapacity", "ServiceNamespace": "ec2" } }

YAML

SpotFleetScalingTarget: Type: 'AWS::ApplicationAutoScaling::ScalableTarget' Properties: MaxCapacity: 2 MinCapacity: 1 ResourceId: !Join - / - - spot-fleet-request - !Ref ECSSpotFleet RoleARN: !GetAtt - AutoScalingRole - Arn ScalableDimension: 'ec2:spot-fleet-request:TargetCapacity' ServiceNamespace: ec2

带 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

本页内容: