put_scaling_policy
async
¶
put_scaling_policy(
*,
config_overrides: Optional[AsyncAutoScalingClientConfig] = None,
auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
policy_name: Optional[XmlStringMaxLen255] = None,
policy_type: Optional[XmlStringMaxLen64] = None,
adjustment_type: Optional[XmlStringMaxLen255] = None,
min_adjustment_step: Optional[MinAdjustmentStep] = None,
min_adjustment_magnitude: Optional[MinAdjustmentMagnitude] = None,
scaling_adjustment: Optional[PolicyIncrement] = None,
cooldown: Optional[Cooldown] = None,
metric_aggregation_type: Optional[XmlStringMaxLen32] = None,
step_adjustments: Optional[StepAdjustments] = None,
estimated_instance_warmup: Optional[EstimatedInstanceWarmup] = None,
target_tracking_configuration: Optional[TargetTrackingConfiguration] = None,
enabled: Optional[ScalingPolicyEnabled] = None,
predictive_scaling_configuration: Optional[PredictiveScalingConfiguration] = None,
) -> PolicyARNType
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.
Parameters:
-
auto_scaling_group_name(Optional[XmlStringMaxLen255], default:None) –The name of the Auto Scaling group.
-
policy_name(Optional[XmlStringMaxLen255], default:None) –The name of the policy.
-
policy_type(Optional[XmlStringMaxLen64], default:None) –One of the following policy types:
-
TargetTrackingScaling -
StepScaling -
SimpleScaling(default) -
PredictiveScaling
-
-
adjustment_type(Optional[XmlStringMaxLen255], default:None) –Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage). The valid values are
ChangeInCapacity,ExactCapacity, andPercentChangeInCapacity.Required if the policy type is
StepScalingorSimpleScaling. For more information, see Scaling adjustment types in the Amazon EC2 Auto Scaling User Guide. -
min_adjustment_step(Optional[MinAdjustmentStep], default:None) –Available for backward compatibility. Use
MinAdjustmentMagnitudeinstead. -
min_adjustment_magnitude(Optional[MinAdjustmentMagnitude], default:None) –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 aMinAdjustmentMagnitudeof 2. If the group has 4 instances and the scaling policy is performed, 25 percent of 4 is 1. However, because you specified aMinAdjustmentMagnitudeof 2, Amazon EC2 Auto Scaling scales out the group by 2 instances.Valid only if the policy type is
StepScalingorSimpleScaling. 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
MinAdjustmentMagnitudeto a value that is at least as large as your largest instance weight. -
scaling_adjustment(Optional[PolicyIncrement], default:None) –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.) -
cooldown(Optional[Cooldown], default:None) –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
-
metric_aggregation_type(Optional[XmlStringMaxLen32], default:None) –The aggregation type for the CloudWatch metrics. The valid values are
Minimum,Maximum, andAverage. If the aggregation type is null, the value is treated asAverage.Valid only if the policy type is
StepScaling. -
step_adjustments(Optional[StepAdjustments], default:None) –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.) -
estimated_instance_warmup(Optional[EstimatedInstanceWarmup], default:None) –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
TargetTrackingScalingorStepScaling.The default is to use the value for the default instance warmup defined for the group. If default instance warmup is null, then
EstimatedInstanceWarmupfalls back to the value of default cooldown. -
target_tracking_configuration(Optional[TargetTrackingConfiguration], default:None) –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
ALBRequestCountPerTargetfor the metric, you must specify theResourceLabelproperty with thePredefinedMetricSpecification.For more information, see TargetTrackingConfiguration in the Amazon EC2 Auto Scaling API Reference.
Required if the policy type is
TargetTrackingScaling. -
-
enabled(Optional[ScalingPolicyEnabled], default:None) –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.
-
predictive_scaling_configuration(Optional[PredictiveScalingConfiguration], default:None) –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.
Raises:
-
LimitExceededFault–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–You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).
-
ServiceLinkedRoleFailure–The service-linked role is not yet ready for use.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To add a scaling policy to an Auto Scaling group This example adds the specified policy to the specified Auto Scaling group.
>>> await client.put_scaling_policy(auto_scaling_group_name='my-auto-scaling-group', policy_name='alb1000-target-tracking-scaling-policy', policy_type='TargetTrackingScaling', target_tracking_configuration={'TargetValue': 1000.0, 'PredefinedMetricSpecification': {'PredefinedMetricType': 'ALBRequestCountPerTarget', 'ResourceLabel': 'app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff'}})
Source code in docs_src/capo_auto_scaling/_services/async_auto_scaling.py
4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 | |