Skip to content

execute_policy async

execute_policy(
    *,
    config_overrides: Optional[AsyncAutoScalingClientConfig] = None,
    auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
    policy_name: Optional[ResourceName] = None,
    honor_cooldown: Optional[HonorCooldown] = None,
    metric_value: Optional[MetricScale] = None,
    breach_threshold: Optional[MetricScale] = None,
) -> None

Executes the specified policy. This can be useful for testing the design of your scaling policy.

Parameters:

  • auto_scaling_group_name (Optional[XmlStringMaxLen255], default: None ) –

    The name of the Auto Scaling group.

  • policy_name (Optional[ResourceName], default: None ) –

    The name or ARN of the policy.

  • honor_cooldown (Optional[HonorCooldown], default: None ) –

    Indicates whether Amazon EC2 Auto Scaling waits for the cooldown period to complete before executing the policy.

    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.

  • metric_value (Optional[MetricScale], default: None ) –

    The metric value to compare to BreachThreshold. This enables you to execute a policy of type StepScaling and determine which step adjustment to use. For example, if the breach threshold is 50 and you want to use a step adjustment with a lower bound of 0 and an upper bound of 10, you can set the metric value to 59.

    If you specify a metric value that doesn't correspond to a step adjustment for the policy, the call returns an error.

    Required if the policy type is StepScaling and not supported otherwise.

  • breach_threshold (Optional[MetricScale], default: None ) –

    The breach threshold for the alarm.

    Required if the policy type is StepScaling and not supported otherwise.

Raises:

  • ResourceContentionFault –

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

  • ScalingActivityInProgressFault –

    The operation can't be performed because there are scaling activities in progress.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To execute a scaling policy This example executes the specified policy.

>>> await client.execute_policy(auto_scaling_group_name='my-auto-scaling-group', policy_name='my-step-scale-out-policy', breach_threshold=50.0, metric_value=59.0)
Source code in docs_src/capo_auto_scaling/_services/async_auto_scaling.py
async def execute_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.resource_name.ResourceName"
    ] = None,
    honor_cooldown: Optional[
        "capo_auto_scaling.types.honor_cooldown.HonorCooldown"
    ] = None,
    metric_value: Optional[
        "capo_auto_scaling.types.metric_scale.MetricScale"
    ] = None,
    breach_threshold: Optional[
        "capo_auto_scaling.types.metric_scale.MetricScale"
    ] = None,
) -> None:
    """<p>Executes the specified policy. This can be useful for testing the design of your scaling policy.</p>

    Args:
        auto_scaling_group_name: <p>The name of the Auto Scaling group.</p>
        policy_name: <p>The name or ARN of the policy.</p>
        honor_cooldown: <p>Indicates whether Amazon EC2 Auto Scaling waits for the cooldown period to complete before executing the policy.</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>
        metric_value: <p>The metric value to compare to <code>BreachThreshold</code>. This enables you to execute a policy of type <code>StepScaling</code> and determine which step adjustment to use. For example, if the breach threshold is 50 and you want to use a step adjustment with a lower bound of 0 and an upper bound of 10, you can set the metric value to 59.</p> <p>If you specify a metric value that doesn't correspond to a step adjustment for the policy, the call returns an error.</p> <p>Required if the policy type is <code>StepScaling</code> and not supported otherwise.</p>
        breach_threshold: <p>The breach threshold for the alarm.</p> <p>Required if the policy type is <code>StepScaling</code> and not supported otherwise.</p>

    Raises:
        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.scaling_activity_in_progress_fault.ScalingActivityInProgressFault: <p>The operation can't be performed because there are scaling activities in progress.</p>
        capo_auto_scaling.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To execute a scaling policy
        This example executes the specified policy.

        >>> await client.execute_policy(auto_scaling_group_name='my-auto-scaling-group', policy_name='my-step-scale-out-policy', breach_threshold=50.0, metric_value=59.0)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_auto_scaling.types.execute_policy_type.ExecutePolicyType]",
    ) -> AsyncOperationResponse[None]:
        import capo_auto_scaling._operations.auto_scaling_2011_01_01.execute_policy

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ExecutePolicy")
    )
    input_: capo_auto_scaling.types.execute_policy_type.ExecutePolicyType = {}
    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 honor_cooldown is not None:
        input_["honor_cooldown"] = honor_cooldown
    if metric_value is not None:
        input_["metric_value"] = metric_value
    if breach_threshold is not None:
        input_["breach_threshold"] = breach_threshold

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