put_scaling_policy
¶
put_scaling_policy(
*,
config_overrides: Optional[AutoScalingClientConfig] = 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 -
ASGAverageCPUUtilizationHighResolution -
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.
>>> 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/auto_scaling.py
4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 | |