Skip to content

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, 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.

  • min_adjustment_step (Optional[MinAdjustmentStep], default: None ) –

    Available for backward compatibility. Use MinAdjustmentMagnitude instead.

  • 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 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.

  • 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, and Average. If the aggregation type is null, the value is treated as Average.

    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 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.

  • 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 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.

  • 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
async def put_scaling_policy(
    self,
    *,
    config_overrides: Optional[AsyncAutoScalingClientConfig] = None,
    auto_scaling_group_name: Optional[
        "capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
    ] = None,
    policy_name: Optional[
        "capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
    ] = None,
    policy_type: Optional[
        "capo_auto_scaling.types.xml_string_max_len64.XmlStringMaxLen64"
    ] = None,
    adjustment_type: Optional[
        "capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
    ] = None,
    min_adjustment_step: Optional[
        "capo_auto_scaling.types.min_adjustment_step.MinAdjustmentStep"
    ] = None,
    min_adjustment_magnitude: Optional[
        "capo_auto_scaling.types.min_adjustment_magnitude.MinAdjustmentMagnitude"
    ] = None,
    scaling_adjustment: Optional[
        "capo_auto_scaling.types.policy_increment.PolicyIncrement"
    ] = None,
    cooldown: Optional["capo_auto_scaling.types.cooldown.Cooldown"] = None,
    metric_aggregation_type: Optional[
        "capo_auto_scaling.types.xml_string_max_len32.XmlStringMaxLen32"
    ] = None,
    step_adjustments: Optional[
        "capo_auto_scaling.types.step_adjustments.StepAdjustments"
    ] = None,
    estimated_instance_warmup: Optional[
        "capo_auto_scaling.types.estimated_instance_warmup.EstimatedInstanceWarmup"
    ] = None,
    target_tracking_configuration: Optional[
        "capo_auto_scaling.types.target_tracking_configuration.TargetTrackingConfiguration"
    ] = None,
    enabled: Optional[
        "capo_auto_scaling.types.scaling_policy_enabled.ScalingPolicyEnabled"
    ] = None,
    predictive_scaling_configuration: Optional[
        "capo_auto_scaling.types.predictive_scaling_configuration.PredictiveScalingConfiguration"
    ] = None,
) -> "capo_auto_scaling.types.policy_arn_type.PolicyARNType":
    """<p>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. </p> <p>For more information about using dynamic scaling, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html">Target tracking scaling policies</a> and <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-simple-step.html">Step and simple scaling policies</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p> <p>For more information about using predictive scaling, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-predictive-scaling.html">Predictive scaling for Amazon EC2 Auto Scaling</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p> <p>You can view the scaling policies for an Auto Scaling group using the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribePolicies.html">DescribePolicies</a> API call. If you are no longer using a scaling policy, you can delete it by calling the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DeletePolicy.html">DeletePolicy</a> API.</p>

    Args:
        auto_scaling_group_name: <p>The name of the Auto Scaling group.</p>
        policy_name: <p>The name of the policy.</p>
        policy_type: <p>One of the following policy types: </p> <ul> <li> <p> <code>TargetTrackingScaling</code> </p> </li> <li> <p> <code>StepScaling</code> </p> </li> <li> <p> <code>SimpleScaling</code> (default)</p> </li> <li> <p> <code>PredictiveScaling</code> </p> </li> </ul>
        adjustment_type: <p>Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage). The valid values are <code>ChangeInCapacity</code>, <code>ExactCapacity</code>, and <code>PercentChangeInCapacity</code>.</p> <p>Required if the policy type is <code>StepScaling</code> or <code>SimpleScaling</code>. For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-simple-step.html#as-scaling-adjustment">Scaling adjustment types</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p>
        min_adjustment_step: <p>Available for backward compatibility. Use <code>MinAdjustmentMagnitude</code> instead.</p>
        min_adjustment_magnitude: <p>The minimum value to scale by when the adjustment type is <code>PercentChangeInCapacity</code>. For example, suppose that you create a step scaling policy to scale out an Auto Scaling group by 25 percent and you specify a <code>MinAdjustmentMagnitude</code> 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 <code>MinAdjustmentMagnitude</code> of 2, Amazon EC2 Auto Scaling scales out the group by 2 instances.</p> <p>Valid only if the policy type is <code>StepScaling</code> or <code>SimpleScaling</code>. For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-simple-step.html#as-scaling-adjustment">Scaling adjustment types</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p> <note> <p>Some Auto Scaling groups use instance weights. In this case, set the <code>MinAdjustmentMagnitude</code> to a value that is at least as large as your largest instance weight.</p> </note>
        scaling_adjustment: <p>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.</p> <p>Required if the policy type is <code>SimpleScaling</code>. (Not used with any other policy type.) </p>
        cooldown: <p>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.</p> <p>Valid only if the policy type is <code>SimpleScaling</code>. For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scaling-cooldowns.html">Scaling cooldowns for Amazon EC2 Auto Scaling</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p> <p>Default: None</p>
        metric_aggregation_type: <p>The aggregation type for the CloudWatch metrics. The valid values are <code>Minimum</code>, <code>Maximum</code>, and <code>Average</code>. If the aggregation type is null, the value is treated as <code>Average</code>.</p> <p>Valid only if the policy type is <code>StepScaling</code>.</p>
        step_adjustments: <p>A set of adjustments that enable you to scale based on the size of the alarm breach.</p> <p>Required if the policy type is <code>StepScaling</code>. (Not used with any other policy type.) </p>
        estimated_instance_warmup: <p> <i>Not needed if the default instance warmup is defined for the group.</i> </p> <p>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.</p> <p>Valid only if the policy type is <code>TargetTrackingScaling</code> or <code>StepScaling</code>.</p> <note> <p>The default is to use the value for the default instance warmup defined for the group. If default instance warmup is null, then <code>EstimatedInstanceWarmup</code> falls back to the value of default cooldown.</p> </note>
        target_tracking_configuration: <p>A target tracking scaling policy. Provides support for predefined or custom metrics.</p> <p>The following predefined metrics are available:</p> <ul> <li> <p> <code>ASGAverageCPUUtilization</code> </p> </li> <li> <p> <code>ASGAverageNetworkIn</code> </p> </li> <li> <p> <code>ASGAverageNetworkOut</code> </p> </li> <li> <p> <code>ALBRequestCountPerTarget</code> </p> </li> </ul> <p>If you specify <code>ALBRequestCountPerTarget</code> for the metric, you must specify the <code>ResourceLabel</code> property with the <code>PredefinedMetricSpecification</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_TargetTrackingConfiguration.html">TargetTrackingConfiguration</a> in the <i>Amazon EC2 Auto Scaling API Reference</i>.</p> <p>Required if the policy type is <code>TargetTrackingScaling</code>.</p>
        enabled: <p>Indicates whether the scaling policy is enabled or disabled. The default is enabled. For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-enable-disable-scaling-policy.html">Disable a scaling policy for an Auto Scaling group</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p>
        predictive_scaling_configuration: <p>A predictive scaling policy. Provides support for predefined and custom metrics.</p> <p>Predefined metrics include CPU utilization, network in/out, and the Application Load Balancer request count.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_PredictiveScalingConfiguration.html">PredictiveScalingConfiguration</a> in the <i>Amazon EC2 Auto Scaling API Reference</i>.</p> <p>Required if the policy type is <code>PredictiveScaling</code>.</p>

    Raises:
        capo_auto_scaling.errors.limit_exceeded_fault.LimitExceededFault: <p>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 <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeAccountLimits.html">DescribeAccountLimits</a> in the <i>Amazon EC2 Auto Scaling API Reference</i>.</p>
        capo_auto_scaling.errors.resource_contention_fault.ResourceContentionFault: <p>You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).</p>
        capo_auto_scaling.errors.service_linked_role_failure.ServiceLinkedRoleFailure: <p>The service-linked role is not yet ready for use.</p>
        capo_auto_scaling.errors.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'}})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_auto_scaling.types.put_scaling_policy_type.PutScalingPolicyType]",
    ) -> AsyncOperationResponse[
        "capo_auto_scaling.types.policy_arn_type.PolicyARNType"
    ]:
        import capo_auto_scaling._operations.auto_scaling_2011_01_01.put_scaling_policy

        (
            output,
            http_response,
        ) = await capo_auto_scaling._operations.auto_scaling_2011_01_01.put_scaling_policy.async_put_scaling_policy(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutScalingPolicy")
    )
    input_: capo_auto_scaling.types.put_scaling_policy_type.PutScalingPolicyType = {}
    if auto_scaling_group_name is not None:
        input_["auto_scaling_group_name"] = auto_scaling_group_name
    if policy_name is not None:
        input_["policy_name"] = policy_name
    if policy_type is not None:
        input_["policy_type"] = policy_type
    if adjustment_type is not None:
        input_["adjustment_type"] = adjustment_type
    if min_adjustment_step is not None:
        input_["min_adjustment_step"] = min_adjustment_step
    if min_adjustment_magnitude is not None:
        input_["min_adjustment_magnitude"] = min_adjustment_magnitude
    if scaling_adjustment is not None:
        input_["scaling_adjustment"] = scaling_adjustment
    if cooldown is not None:
        input_["cooldown"] = cooldown
    if metric_aggregation_type is not None:
        input_["metric_aggregation_type"] = metric_aggregation_type
    if step_adjustments is not None:
        input_["step_adjustments"] = step_adjustments
    if estimated_instance_warmup is not None:
        input_["estimated_instance_warmup"] = estimated_instance_warmup
    if target_tracking_configuration is not None:
        input_["target_tracking_configuration"] = target_tracking_configuration
    if enabled is not None:
        input_["enabled"] = enabled
    if predictive_scaling_configuration is not None:
        input_["predictive_scaling_configuration"] = (
            predictive_scaling_configuration
        )

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output