- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
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
PutScalingPolicyCommand Input
Parameter | Type | Description |
---|
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 Required if the policy type is |
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 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 The default is to use the value for the default instance warmup defined for the group. If default instance warmup is null, then |
MetricAggregationType | string | undefined | The aggregation type for the CloudWatch metrics. The valid values are Valid only if the policy type is |
MinAdjustmentMagnitude | number | undefined | The minimum value to scale by when the adjustment type is Valid only if the policy type is Some Auto Scaling groups use instance weights. In this case, set the |
MinAdjustmentStep | number | undefined | Available for backward compatibility. Use |
PolicyType | string | undefined | One of the following policy types:
|
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 |
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 |
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 |
TargetTrackingConfiguration | TargetTrackingConfiguration | undefined | A target tracking scaling policy. Provides support for predefined or custom metrics. The following predefined metrics are available:
If you specify For more information, see TargetTrackingConfiguration in the Amazon EC2 Auto Scaling API Reference. Required if the policy type is |
PutScalingPolicyCommand Output
Parameter | Type | Description |
---|
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 |
---|
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. |