Example scaling policies for the Amazon Command Line Interface (Amazon CLI)
You can create scaling policies for Amazon EC2 Auto Scaling through the Amazon Web Services Management Console, Amazon CLI, or SDKs.
The following examples show how you can create scaling policies for Amazon EC2 Auto Scaling with the Amazon CLI put-scaling-policy command. For introductory exercises for creating scaling policies from the Amazon CLI, see Target tracking scaling policies and Step and simple scaling policies.
Example 1: To apply a target tracking scaling policy with a predefined metric specification
aws autoscaling put-scaling-policy --policy-name
cpu40-target-tracking-scaling-policy
\ --auto-scaling-group-namemy-asg
--policy-type TargetTrackingScaling \ --target-tracking-configurationfile://config.json
{ "TargetValue":40.0
, "PredefinedMetricSpecification": { "PredefinedMetricType": "ASGAverageCPUUtilization
" } }
Example 2: To apply a target tracking scaling policy with a customized metric specification
aws autoscaling put-scaling-policy --policy-name
sqs100-target-tracking-scaling-policy
\ --auto-scaling-group-namemy-asg
--policy-type TargetTrackingScaling \ --target-tracking-configurationfile://config.json
{ "TargetValue":100.0
, "CustomizedMetricSpecification": { "MetricName": "MyBacklogPerInstance
", "Namespace": "MyNamespace
", "Dimensions": [{ "Name": "MyOptionalMetricDimensionName
", "Value": "MyOptionalMetricDimensionValue
" }], "Statistic": "Average
", "Unit": "None
" } }
Example 3: To apply a target tracking scaling policy for scale out only
aws autoscaling put-scaling-policy --policy-name
alb1000-target-tracking-scaling-policy
\ --auto-scaling-group-namemy-asg
--policy-type TargetTrackingScaling \ --target-tracking-configurationfile://config.json
{ "TargetValue":1000.0
, "PredefinedMetricSpecification": { "PredefinedMetricType": "ALBRequestCountPerTarget
", "ResourceLabel": "app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff
" }, "DisableScaleIn": true }
Example 4: To apply a step scaling policy for scale out
aws autoscaling put-scaling-policy \ --auto-scaling-group-name
my-asg
\ --policy-namemy-step-scale-out-policy
\ --policy-type StepScaling \ --adjustment-typePercentChangeInCapacity
\ --metric-aggregation-typeAverage
\ --step-adjustments MetricIntervalLowerBound=10.0
,MetricIntervalUpperBound=20.0
,ScalingAdjustment=10
\ MetricIntervalLowerBound=20.0
,MetricIntervalUpperBound=30.0
,ScalingAdjustment=20
\ MetricIntervalLowerBound=30.0
,ScalingAdjustment=30
\ --min-adjustment-magnitude1
Record the policy's Amazon Resource Name (ARN). You need the ARN when you create the CloudWatch alarm.
Example 5: To apply a step scaling policy for scale in
aws autoscaling put-scaling-policy \ --auto-scaling-group-name
my-asg
\ --policy-namemy-step-scale-in-policy
\ --policy-type StepScaling \ --adjustment-typeChangeInCapacity
\ --step-adjustments MetricIntervalUpperBound=0.0
,ScalingAdjustment=-2
Record the policy's Amazon Resource Name (ARN). You need the ARN when you create the CloudWatch alarm.
Example 6: To apply a simple scaling policy for scale out
aws autoscaling put-scaling-policy --policy-name
my-simple-scale-out-policy
\ --auto-scaling-group-namemy-asg
--scaling-adjustment30
\ --adjustment-typePercentChangeInCapacity
--min-adjustment-magnitude2
Record the policy's Amazon Resource Name (ARN). You need the ARN when you create the CloudWatch alarm.
Example 7: To apply a simple scaling policy for scale in
aws autoscaling put-scaling-policy --policy-name
my-simple-scale-in-policy
\ --auto-scaling-group-namemy-asg
--scaling-adjustment-1
\ --adjustment-typeChangeInCapacity
--cooldown180
Record the policy's Amazon Resource Name (ARN). You need the ARN when you create the CloudWatch alarm.