PutScalingPolicyCommand

Creates or updates a scaling policy for an Auto Scaling group. Scaling policies are used to scale an Auto Scaling group based on configurable metrics. If no policies are defined, the dynamic scaling and predictive scaling features are not used.

For more information about using dynamic scaling, see Target tracking scaling policies  and Step and simple scaling policies  in the Amazon EC2 Auto Scaling User Guide.

For more information about using predictive scaling, see Predictive scaling for Amazon EC2 Auto Scaling  in the Amazon EC2 Auto Scaling User Guide.

You can view the scaling policies for an Auto Scaling group using the DescribePolicies  API call. If you are no longer using a scaling policy, you can delete it by calling the DeletePolicy  API.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { AutoScalingClient, PutScalingPolicyCommand } from "@aws-sdk/client-auto-scaling"; // ES Modules import
// const { AutoScalingClient, PutScalingPolicyCommand } = require("@aws-sdk/client-auto-scaling"); // CommonJS import
const client = new AutoScalingClient(config);
const input = { // PutScalingPolicyType
  AutoScalingGroupName: "STRING_VALUE", // required
  PolicyName: "STRING_VALUE", // required
  PolicyType: "STRING_VALUE",
  AdjustmentType: "STRING_VALUE",
  MinAdjustmentStep: Number("int"),
  MinAdjustmentMagnitude: Number("int"),
  ScalingAdjustment: Number("int"),
  Cooldown: Number("int"),
  MetricAggregationType: "STRING_VALUE",
  StepAdjustments: [ // StepAdjustments
    { // StepAdjustment
      MetricIntervalLowerBound: Number("double"),
      MetricIntervalUpperBound: Number("double"),
      ScalingAdjustment: Number("int"), // required
    },
  ],
  EstimatedInstanceWarmup: Number("int"),
  TargetTrackingConfiguration: { // TargetTrackingConfiguration
    PredefinedMetricSpecification: { // PredefinedMetricSpecification
      PredefinedMetricType: "ASGAverageCPUUtilization" || "ASGAverageNetworkIn" || "ASGAverageNetworkOut" || "ALBRequestCountPerTarget", // required
      ResourceLabel: "STRING_VALUE",
    },
    CustomizedMetricSpecification: { // CustomizedMetricSpecification
      MetricName: "STRING_VALUE",
      Namespace: "STRING_VALUE",
      Dimensions: [ // MetricDimensions
        { // MetricDimension
          Name: "STRING_VALUE", // required
          Value: "STRING_VALUE", // required
        },
      ],
      Statistic: "Average" || "Minimum" || "Maximum" || "SampleCount" || "Sum",
      Unit: "STRING_VALUE",
      Period: Number("int"),
      Metrics: [ // TargetTrackingMetricDataQueries
        { // TargetTrackingMetricDataQuery
          Id: "STRING_VALUE", // required
          Expression: "STRING_VALUE",
          MetricStat: { // TargetTrackingMetricStat
            Metric: { // Metric
              Namespace: "STRING_VALUE", // required
              MetricName: "STRING_VALUE", // required
              Dimensions: [
                {
                  Name: "STRING_VALUE", // required
                  Value: "STRING_VALUE", // required
                },
              ],
            },
            Stat: "STRING_VALUE", // required
            Unit: "STRING_VALUE",
            Period: Number("int"),
          },
          Label: "STRING_VALUE",
          Period: Number("int"),
          ReturnData: true || false,
        },
      ],
    },
    TargetValue: Number("double"), // required
    DisableScaleIn: true || false,
  },
  Enabled: true || false,
  PredictiveScalingConfiguration: { // PredictiveScalingConfiguration
    MetricSpecifications: [ // PredictiveScalingMetricSpecifications // required
      { // PredictiveScalingMetricSpecification
        TargetValue: Number("double"), // required
        PredefinedMetricPairSpecification: { // PredictiveScalingPredefinedMetricPair
          PredefinedMetricType: "ASGCPUUtilization" || "ASGNetworkIn" || "ASGNetworkOut" || "ALBRequestCount", // required
          ResourceLabel: "STRING_VALUE",
        },
        PredefinedScalingMetricSpecification: { // PredictiveScalingPredefinedScalingMetric
          PredefinedMetricType: "ASGAverageCPUUtilization" || "ASGAverageNetworkIn" || "ASGAverageNetworkOut" || "ALBRequestCountPerTarget", // required
          ResourceLabel: "STRING_VALUE",
        },
        PredefinedLoadMetricSpecification: { // PredictiveScalingPredefinedLoadMetric
          PredefinedMetricType: "ASGTotalCPUUtilization" || "ASGTotalNetworkIn" || "ASGTotalNetworkOut" || "ALBTargetGroupRequestCount", // required
          ResourceLabel: "STRING_VALUE",
        },
        CustomizedScalingMetricSpecification: { // PredictiveScalingCustomizedScalingMetric
          MetricDataQueries: [ // MetricDataQueries // required
            { // MetricDataQuery
              Id: "STRING_VALUE", // required
              Expression: "STRING_VALUE",
              MetricStat: { // MetricStat
                Metric: {
                  Namespace: "STRING_VALUE", // required
                  MetricName: "STRING_VALUE", // required
                  Dimensions: "<MetricDimensions>",
                },
                Stat: "STRING_VALUE", // required
                Unit: "STRING_VALUE",
              },
              Label: "STRING_VALUE",
              ReturnData: true || false,
            },
          ],
        },
        CustomizedLoadMetricSpecification: { // PredictiveScalingCustomizedLoadMetric
          MetricDataQueries: [ // required
            {
              Id: "STRING_VALUE", // required
              Expression: "STRING_VALUE",
              MetricStat: {
                Metric: {
                  Namespace: "STRING_VALUE", // required
                  MetricName: "STRING_VALUE", // required
                  Dimensions: "<MetricDimensions>",
                },
                Stat: "STRING_VALUE", // required
                Unit: "STRING_VALUE",
              },
              Label: "STRING_VALUE",
              ReturnData: true || false,
            },
          ],
        },
        CustomizedCapacityMetricSpecification: { // PredictiveScalingCustomizedCapacityMetric
          MetricDataQueries: [ // required
            {
              Id: "STRING_VALUE", // required
              Expression: "STRING_VALUE",
              MetricStat: {
                Metric: {
                  Namespace: "STRING_VALUE", // required
                  MetricName: "STRING_VALUE", // required
                  Dimensions: "<MetricDimensions>",
                },
                Stat: "STRING_VALUE", // required
                Unit: "STRING_VALUE",
              },
              Label: "STRING_VALUE",
              ReturnData: true || false,
            },
          ],
        },
      },
    ],
    Mode: "ForecastAndScale" || "ForecastOnly",
    SchedulingBufferTime: Number("int"),
    MaxCapacityBreachBehavior: "HonorMaxCapacity" || "IncreaseMaxCapacity",
    MaxCapacityBuffer: Number("int"),
  },
};
const command = new PutScalingPolicyCommand(input);
const response = await client.send(command);
// { // PolicyARNType
//   PolicyARN: "STRING_VALUE",
//   Alarms: [ // Alarms
//     { // Alarm
//       AlarmName: "STRING_VALUE",
//       AlarmARN: "STRING_VALUE",
//     },
//   ],
// };

Example Usage

// This example adds the specified policy to the specified Auto Scaling group.
const input = {
"AutoScalingGroupName": "my-auto-scaling-group",
"PolicyName": "alb1000-target-tracking-scaling-policy",
"PolicyType": "TargetTrackingScaling",
"TargetTrackingConfiguration": {
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ALBRequestCountPerTarget",
"ResourceLabel": "app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff"
},
"TargetValue": 1000
}
};
const command = new PutScalingPolicyCommand(input);
const response = await client.send(command);
/* response ==
{
"Alarms": [
{
"AlarmARN": "arn:aws:cloudwatch:us-west-2:123456789012:alarm:TargetTracking-my-asg-AlarmHigh-fc0e4183-23ac
          -497e-9992-691c9980c38e",
"AlarmName": "TargetTracking-my-asg-AlarmHigh-fc0e4183-23ac-497e-9992-691c9980c38e"
},
{
"AlarmARN": "arn:aws:cloudwatch:us-west-2:123456789012:alarm:TargetTracking-my-asg-AlarmLow-61a39305-ed0c
          -47af-bd9e-471a352ee1a2",
"AlarmName": "TargetTracking-my-asg-AlarmLow-61a39305-ed0c-47af-bd9e-471a352ee1a2"
}
],
"PolicyARN": "arn:aws:autoscaling:us-west-2:123456789012:scalingPolicy:228f02c2-c665-4bfd-aaac-8b04080bea3c
      :autoScalingGroupName/my-auto-scaling-group:policyName/alb1000-target-tracking-scaling-policy"
}
*\/
// example id: autoscaling-put-scaling-policy-1
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JavaScriptLn 1, Col 1
Errors: 0 Warnings: 0

PutScalingPolicyCommand Input

See PutScalingPolicyCommandInput for more details

Parameter
Type
Description
AutoScalingGroupName
Required
string | undefined

The name of the Auto Scaling group.

PolicyName
Required
string | undefined

The name of the policy.

AdjustmentType
string | undefined

Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage). The valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity.

Required if the policy type is StepScaling or SimpleScaling. For more information, see Scaling adjustment types  in the Amazon EC2 Auto Scaling User Guide.

Cooldown
number | undefined

A cooldown period, in seconds, that applies to a specific simple scaling policy. When a cooldown period is specified here, it overrides the default cooldown.

Valid only if the policy type is SimpleScaling. For more information, see Scaling cooldowns for Amazon EC2 Auto Scaling  in the Amazon EC2 Auto Scaling User Guide.

Default: None

Enabled
boolean | undefined

Indicates whether the scaling policy is enabled or disabled. The default is enabled. For more information, see Disable a scaling policy for an Auto Scaling group  in the Amazon EC2 Auto Scaling User Guide.

EstimatedInstanceWarmup
number | undefined

Not needed if the default instance warmup is defined for the group.

The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics. This warm-up period applies to instances launched due to a specific target tracking or step scaling policy. When a warm-up period is specified here, it overrides the default instance warmup.

Valid only if the policy type is TargetTrackingScaling or StepScaling.

The default is to use the value for the default instance warmup defined for the group. If default instance warmup is null, then EstimatedInstanceWarmup falls back to the value of default cooldown.

MetricAggregationType
string | undefined

The aggregation type for the CloudWatch metrics. The valid values are Minimum, Maximum, and Average. If the aggregation type is null, the value is treated as Average.

Valid only if the policy type is StepScaling.

MinAdjustmentMagnitude
number | undefined

The minimum value to scale by when the adjustment type is PercentChangeInCapacity. For example, suppose that you create a step scaling policy to scale out an Auto Scaling group by 25 percent and you specify a MinAdjustmentMagnitude of 2. If the group has 4 instances and the scaling policy is performed, 25 percent of 4 is 1. However, because you specified a MinAdjustmentMagnitude of 2, Amazon EC2 Auto Scaling scales out the group by 2 instances.

Valid only if the policy type is StepScaling or SimpleScaling. For more information, see Scaling adjustment types  in the Amazon EC2 Auto Scaling User Guide.

Some Auto Scaling groups use instance weights. In this case, set the MinAdjustmentMagnitude to a value that is at least as large as your largest instance weight.

MinAdjustmentStep
number | undefined

Available for backward compatibility. Use MinAdjustmentMagnitude instead.

PolicyType
string | undefined

One of the following policy types:

  • TargetTrackingScaling

  • StepScaling

  • SimpleScaling (default)

  • PredictiveScaling

PredictiveScalingConfiguration
PredictiveScalingConfiguration | undefined

A predictive scaling policy. Provides support for predefined and custom metrics.

Predefined metrics include CPU utilization, network in/out, and the Application Load Balancer request count.

For more information, see PredictiveScalingConfiguration  in the Amazon EC2 Auto Scaling API Reference.

Required if the policy type is PredictiveScaling.

ScalingAdjustment
number | undefined

The amount by which to scale, based on the specified adjustment type. A positive value adds to the current capacity while a negative number removes from the current capacity. For exact capacity, you must specify a non-negative value.

Required if the policy type is SimpleScaling. (Not used with any other policy type.)

StepAdjustments
StepAdjustment[] | undefined

A set of adjustments that enable you to scale based on the size of the alarm breach.

Required if the policy type is StepScaling. (Not used with any other policy type.)

TargetTrackingConfiguration
TargetTrackingConfiguration | undefined

A target tracking scaling policy. Provides support for predefined or custom metrics.

The following predefined metrics are available:

  • ASGAverageCPUUtilization

  • ASGAverageNetworkIn

  • ASGAverageNetworkOut

  • ALBRequestCountPerTarget

If you specify ALBRequestCountPerTarget for the metric, you must specify the ResourceLabel property with the PredefinedMetricSpecification.

For more information, see TargetTrackingConfiguration  in the Amazon EC2 Auto Scaling API Reference.

Required if the policy type is TargetTrackingScaling.

PutScalingPolicyCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
Alarms
Alarm[] | undefined

The CloudWatch alarms created for the target tracking scaling policy.

PolicyARN
string | undefined

The Amazon Resource Name (ARN) of the policy.

Throws

Name
Fault
Details
LimitExceededFault
client

You have already reached a limit for your Amazon EC2 Auto Scaling resources (for example, Auto Scaling groups, launch configurations, or lifecycle hooks). For more information, see DescribeAccountLimits  in the Amazon EC2 Auto Scaling API Reference.

ResourceContentionFault
server

You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).

ServiceLinkedRoleFailure
server

The service-linked role is not yet ready for use.

AutoScalingServiceException
Base exception class for all service exceptions from AutoScaling service.