Skip to content

terminate_instance_in_auto_scaling_group async

terminate_instance_in_auto_scaling_group(
    *,
    config_overrides: Optional[AsyncAutoScalingClientConfig] = None,
    instance_id: Optional[XmlStringMaxLen19] = None,
    instance_ids: Optional[TerminationInstanceIds] = None,
    auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
    should_decrement_desired_capacity: Optional[ShouldDecrementDesiredCapacity] = None,
) -> ActivityType

Terminates the specified instance and optionally adjusts the desired group size. This operation cannot be called on instances in a warm pool.

This call simply makes a termination request. The instances are not terminated immediately. When an instance is terminated, the instance status changes to terminated. You can't connect to or start an instance after you've terminated it.

If you do not specify the option to decrement the desired capacity, Amazon EC2 Auto Scaling launches instances to replace the ones that are terminated.

To terminate multiple instances in a single call, use the InstanceIds and AutoScalingGroupName parameters instead of InstanceId. When terminating multiple instances, the response populates Activities instead of Activity.

By default, Amazon EC2 Auto Scaling balances instances across all Availability Zones. If you decrement the desired capacity, your Auto Scaling group can become unbalanced between Availability Zones. Amazon EC2 Auto Scaling tries to rebalance the group, and rebalancing might terminate instances in other zones. For more information, see Manual scaling in the Amazon EC2 Auto Scaling User Guide.

Parameters:

  • instance_id (Optional[XmlStringMaxLen19], default: None ) –

    The ID of the instance.

  • instance_ids (Optional[TerminationInstanceIds], default: None ) –

    The IDs of the instances. You can specify up to 100 instances.

    This parameter requires that you also specify AutoScalingGroupName.

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

    The name of the Auto Scaling group. Required when using InstanceIds.

  • should_decrement_desired_capacity (Optional[ShouldDecrementDesiredCapacity], default: None ) –

    Indicates whether terminating the instance also decrements the size of the Auto Scaling group.

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 terminate an instance in an Auto Scaling group This example terminates the specified instance from the specified Auto Scaling group without updating the size of the group. Auto Scaling launches a replacement instance after the specified instance terminates.

>>> await client.terminate_instance_in_auto_scaling_group(instance_id='i-93633f9b', should_decrement_desired_capacity=False)
To terminate multiple instances in an Auto Scaling group
This example terminates multiple instances from the specified Auto Scaling group without updating the size of the group. Auto Scaling launches replacement instances after the specified instances terminate.
>>> await client.terminate_instance_in_auto_scaling_group(instance_ids=['i-93633f9b', 'i-ab4d5e6f7'], auto_scaling_group_name='my-asg', should_decrement_desired_capacity=False)
Source code in docs_src/capo_auto_scaling/_services/async_auto_scaling.py
async def terminate_instance_in_auto_scaling_group(
    self,
    *,
    config_overrides: Optional[AsyncAutoScalingClientConfig] = None,
    instance_id: Optional[
        "capo_auto_scaling.types.xml_string_max_len19.XmlStringMaxLen19"
    ] = None,
    instance_ids: Optional[
        "capo_auto_scaling.types.termination_instance_ids.TerminationInstanceIds"
    ] = None,
    auto_scaling_group_name: Optional[
        "capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
    ] = None,
    should_decrement_desired_capacity: Optional[
        "capo_auto_scaling.types.should_decrement_desired_capacity.ShouldDecrementDesiredCapacity"
    ] = None,
) -> "capo_auto_scaling.types.activity_type.ActivityType":
    """<p>Terminates the specified instance and optionally adjusts the desired group size. This operation cannot be called on instances in a warm pool.</p> <p>This call simply makes a termination request. The instances are not terminated immediately. When an instance is terminated, the instance status changes to <code>terminated</code>. You can't connect to or start an instance after you've terminated it.</p> <p>If you do not specify the option to decrement the desired capacity, Amazon EC2 Auto Scaling launches instances to replace the ones that are terminated. </p> <p>To terminate multiple instances in a single call, use the <code>InstanceIds</code> and <code>AutoScalingGroupName</code> parameters instead of <code>InstanceId</code>. When terminating multiple instances, the response populates <code>Activities</code> instead of <code>Activity</code>.</p> <p>By default, Amazon EC2 Auto Scaling balances instances across all Availability Zones. If you decrement the desired capacity, your Auto Scaling group can become unbalanced between Availability Zones. Amazon EC2 Auto Scaling tries to rebalance the group, and rebalancing might terminate instances in other zones. 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:
        instance_id: <p>The ID of the instance.</p>
        instance_ids: <p>The IDs of the instances. You can specify up to 100 instances.</p> <p>This parameter requires that you also specify <code>AutoScalingGroupName</code>.</p>
        auto_scaling_group_name: <p>The name of the Auto Scaling group. Required when using <code>InstanceIds</code>.</p>
        should_decrement_desired_capacity: <p>Indicates whether terminating the instance also decrements the size of the Auto Scaling group.</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 terminate an instance in an Auto Scaling group
        This example terminates the specified instance from the specified Auto Scaling group without updating the size of the group. Auto Scaling launches a replacement instance after the specified instance terminates.

        >>> await client.terminate_instance_in_auto_scaling_group(instance_id='i-93633f9b', should_decrement_desired_capacity=False)
        To terminate multiple instances in an Auto Scaling group
        This example terminates multiple instances from the specified Auto Scaling group without updating the size of the group. Auto Scaling launches replacement instances after the specified instances terminate.

        >>> await client.terminate_instance_in_auto_scaling_group(instance_ids=['i-93633f9b', 'i-ab4d5e6f7'], auto_scaling_group_name='my-asg', should_decrement_desired_capacity=False)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_auto_scaling.types.terminate_instance_in_auto_scaling_group_type.TerminateInstanceInAutoScalingGroupType]",
    ) -> AsyncOperationResponse[
        "capo_auto_scaling.types.activity_type.ActivityType"
    ]:
        import capo_auto_scaling._operations.auto_scaling_2011_01_01.terminate_instance_in_auto_scaling_group

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("TerminateInstanceInAutoScalingGroup")
    )
    input_: capo_auto_scaling.types.terminate_instance_in_auto_scaling_group_type.TerminateInstanceInAutoScalingGroupType = {}
    if instance_id is not None:
        input_["instance_id"] = instance_id
    if instance_ids is not None:
        input_["instance_ids"] = instance_ids
    if auto_scaling_group_name is not None:
        input_["auto_scaling_group_name"] = auto_scaling_group_name
    if should_decrement_desired_capacity is not None:
        input_["should_decrement_desired_capacity"] = (
            should_decrement_desired_capacity
        )

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