Example scaling policies for the AWS Command Line Interface (AWS CLI) - Amazon EC2 Auto Scaling

Example scaling policies for the AWS Command Line Interface (AWS CLI)

You can create scaling policies for Amazon EC2 Auto Scaling through the AWS Management Console, AWS CLI, or SDKs.

The following examples show how you can create scaling policies for Amazon EC2 Auto Scaling with the AWS CLI put-scaling-policy command. For introductory exercises for creating scaling policies from the AWS 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-name my-asg --policy-type TargetTrackingScaling \ --target-tracking-configuration file://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-name my-asg --policy-type TargetTrackingScaling \ --target-tracking-configuration file://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-name my-asg --policy-type TargetTrackingScaling \ --target-tracking-configuration file://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-name my-step-scale-out-policy \ --policy-type StepScaling \ --adjustment-type PercentChangeInCapacity \ --metric-aggregation-type Average \ --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-magnitude 1

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-name my-step-scale-in-policy \ --policy-type StepScaling \ --adjustment-type ChangeInCapacity \ --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-name my-asg --scaling-adjustment 30 \ --adjustment-type PercentChangeInCapacity --min-adjustment-magnitude 2

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-name my-asg --scaling-adjustment -1 \ --adjustment-type ChangeInCapacity --cooldown 180

Record the policy's Amazon Resource Name (ARN). You need the ARN when you create the CloudWatch alarm.