Skip to content

set_desired_capacity

set_desired_capacity(
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
    desired_capacity: Optional[AutoScalingGroupDesiredCapacity] = None,
    honor_cooldown: Optional[HonorCooldown] = None,
) -> None

Sets the size of the specified Auto Scaling group.

If a scale-in activity occurs as a result of a new DesiredCapacity value that is lower than the current size of the group, the Auto Scaling group uses its termination policy to determine which instances to terminate.

For more information, see Manual scaling in the Amazon EC2 Auto Scaling User Guide.

Parameters:

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

    The name of the Auto Scaling group.

  • desired_capacity (Optional[AutoScalingGroupDesiredCapacity], default: None ) –

    The desired capacity is the initial capacity of the Auto Scaling group after this operation completes and the capacity it attempts to maintain.

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

    Indicates whether Amazon EC2 Auto Scaling waits for the cooldown period to complete before initiating a scaling activity to set your Auto Scaling group to its new capacity. By default, Amazon EC2 Auto Scaling does not honor the cooldown period during manual scaling activities.

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 set the desired capacity for an Auto Scaling group This example sets the desired capacity for the specified Auto Scaling group.

>>> client.set_desired_capacity(auto_scaling_group_name='my-auto-scaling-group', desired_capacity=2, honor_cooldown=True)
Source code in docs_src/capo_auto_scaling/_services/auto_scaling.py
def set_desired_capacity(
    self,
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    auto_scaling_group_name: Optional[
        "capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
    ] = None,
    desired_capacity: Optional[
        "capo_auto_scaling.types.auto_scaling_group_desired_capacity.AutoScalingGroupDesiredCapacity"
    ] = None,
    honor_cooldown: Optional[
        "capo_auto_scaling.types.honor_cooldown.HonorCooldown"
    ] = None,
) -> None:
    """<p>Sets the size of the specified Auto Scaling group.</p> <p>If a scale-in activity occurs as a result of a new <code>DesiredCapacity</code> value that is lower than the current size of the group, the Auto Scaling group uses its termination policy to determine which instances to terminate. </p> <p>For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scaling-manually.html">Manual scaling</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p>

    Args:
        auto_scaling_group_name: <p>The name of the Auto Scaling group.</p>
        desired_capacity: <p>The desired capacity is the initial capacity of the Auto Scaling group after this operation completes and the capacity it attempts to maintain.</p>
        honor_cooldown: <p>Indicates whether Amazon EC2 Auto Scaling waits for the cooldown period to complete before initiating a scaling activity to set your Auto Scaling group to its new capacity. By default, Amazon EC2 Auto Scaling does not honor the cooldown period during manual scaling activities.</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 set the desired capacity for an Auto Scaling group
        This example sets the desired capacity for the specified Auto Scaling group.

        >>> client.set_desired_capacity(auto_scaling_group_name='my-auto-scaling-group', desired_capacity=2, honor_cooldown=True)
    """

    def _handler(
        req: "OperationRequest[capo_auto_scaling.types.set_desired_capacity_type.SetDesiredCapacityType]",
    ) -> OperationResponse[None]:
        import capo_auto_scaling._operations.auto_scaling_2011_01_01.set_desired_capacity

        output, http_response = (
            capo_auto_scaling._operations.auto_scaling_2011_01_01.set_desired_capacity.set_desired_capacity(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("SetDesiredCapacity")
    )
    input_: capo_auto_scaling.types.set_desired_capacity_type.SetDesiredCapacityType = {}
    if auto_scaling_group_name is not None:
        input_["auto_scaling_group_name"] = auto_scaling_group_name
    if desired_capacity is not None:
        input_["desired_capacity"] = desired_capacity
    if honor_cooldown is not None:
        input_["honor_cooldown"] = honor_cooldown

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output