AWS CloudFormation
User Guide (Version )

AWS::ApplicationAutoScaling::ScalingPolicy

The AWS::ApplicationAutoScaling::ScalingPolicy resource defines a scaling policy that Application Auto Scaling uses to adjust your application resources.

For more information, see PutScalingPolicy in the Application Auto Scaling API Reference. For more information about scaling policies, see the Application Auto Scaling User Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

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

Properties

PolicyName

The name of the scaling policy.

Required: Yes

Type: String

Minimum: 1

Maximum: 256

Pattern: \p{Print}+

Update requires: Replacement

PolicyType

The Application Auto Scaling policy type. Valid values are StepScaling and TargetTrackingScaling.

For DynamoDB, only TargetTrackingScaling is supported. For Amazon ECS, Spot Fleet, and Amazon RDS, both StepScaling and TargetTrackingScaling are supported. For any other service, only StepScaling is supported.

Required: Yes

Type: String

Update requires: No interruption

ResourceId

The unique resource identifier for the scalable target that this scaling policy applies to. For valid values, see the ResourceId parameter for PutScalingPolicy in the Application Auto Scaling API Reference.

You must specify either the ResourceId, ScalableDimension, and ServiceNamespace properties, or the ScalingTargetId property, but not both.

Required: Conditional

Type: String

Update requires: Replacement

ScalableDimension

The scalable dimension of the scalable target that this scaling policy applies to. The scalable dimension contains the service namespace, resource type, and scaling property, such as ecs:service:DesiredCount for the desired task count of an Amazon ECS service. For valid values, see the ScalableDimension parameter for PutScalingPolicy in the Application Auto Scaling API Reference.

You must specify either the ResourceId, ScalableDimension, and ServiceNamespace properties, or the ScalingTargetId property, but not both.

Required: Conditional

Type: String

Update requires: Replacement

ScalingTargetId

The AWS CloudFormation-generated ID of an Application Auto Scaling scalable target. For more information about the ID, see the Return Value section of the AWS::ApplicationAutoScaling::ScalableTarget resource.

You must specify either the ScalingTargetId property, or the ResourceId, ScalableDimension, and ServiceNamespace properties, but not both.

Required: Conditional

Type: String

Update requires: Replacement

ServiceNamespace

The namespace of the AWS service that provides the resource or custom-resource for a resource provided by your own application or service. For valid values, see the ServiceNamespace parameter for PutScalingPolicy in the Application Auto Scaling API Reference.

You must specify either the ResourceId, ScalableDimension, and ServiceNamespace properties, or the ScalingTargetId property, but not both.

Required: Conditional

Type: String

Update requires: Replacement

StepScalingPolicyConfiguration

A step scaling policy.

Required: No

Type: StepScalingPolicyConfiguration

Update requires: No interruption

TargetTrackingScalingPolicyConfiguration

A target tracking scaling policy.

Required: No

Type: TargetTrackingScalingPolicyConfiguration

Update requires: No interruption

Return Values

Ref

When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the Application Auto Scaling scaling policy Amazon Resource Name (ARN). For example: arn:aws:autoscaling:us-east-2:123456789012:scalingPolicy:12ab3c4d-56789-0ef1-2345-6ghi7jk8lm90:resource/ecs/service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH:policyName/MyStepPolicy.

For more information about using the Ref function, see Ref.

Examples

The following examples create scaling policies for a scalable target that is registered with Application Auto Scaling. For more information, see PutScalingPolicy in the Application Auto Scaling API Reference.

Target Tracking Scaling Policy with an Amazon DynamoDB Table

This example both registers a AWS::DynamoDB::Table as a scalable target and defines a TargetTrackingScaling scaling policy that scales the WriteCapacityUnits throughput for the table.

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

Step Scaling Policy for Scale Out

The following example creates a step scaling policy for a specified scalable target. When an associated alarm is triggered, the policy increases the capacity of the scalable target by 200%, with a cooldown period of 60 seconds.

JSON

{ "scalingPolicy":{ "Type":"AWS::ApplicationAutoScaling::ScalingPolicy", "Properties":{ "PolicyName":"MyStepPolicy", "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: MyStepPolicy PolicyType: StepScaling ScalingTargetId: Ref: scalableTarget StepScalingPolicyConfiguration: AdjustmentType: PercentChangeInCapacity Cooldown: 60 MetricAggregationType: Average StepAdjustments: - MetricIntervalLowerBound: 0 ScalingAdjustment: 200