AutoScaling / Client / terminate_instance_in_auto_scaling_group

terminate_instance_in_auto_scaling_group#

AutoScaling.Client.terminate_instance_in_auto_scaling_group(**kwargs)#

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

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.

See also: AWS API Documentation

Request Syntax

response = client.terminate_instance_in_auto_scaling_group(
    InstanceId='string',
    ShouldDecrementDesiredCapacity=True|False
)
Parameters:
  • InstanceId (string) –

    [REQUIRED]

    The ID of the instance.

  • ShouldDecrementDesiredCapacity (boolean) –

    [REQUIRED]

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

Return type:

dict

Returns:

Response Syntax

{
    'Activity': {
        'ActivityId': 'string',
        'AutoScalingGroupName': 'string',
        'Description': 'string',
        'Cause': 'string',
        'StartTime': datetime(2015, 1, 1),
        'EndTime': datetime(2015, 1, 1),
        'StatusCode': 'PendingSpotBidPlacement'|'WaitingForSpotInstanceRequestId'|'WaitingForSpotInstanceId'|'WaitingForInstanceId'|'PreInService'|'InProgress'|'WaitingForELBConnectionDraining'|'MidLifecycleAction'|'WaitingForInstanceWarmup'|'Successful'|'Failed'|'Cancelled'|'WaitingForConnectionDraining',
        'StatusMessage': 'string',
        'Progress': 123,
        'Details': 'string',
        'AutoScalingGroupState': 'string',
        'AutoScalingGroupARN': 'string'
    }
}

Response Structure

  • (dict) –

    • Activity (dict) –

      A scaling activity.

      • ActivityId (string) –

        The ID of the activity.

      • AutoScalingGroupName (string) –

        The name of the Auto Scaling group.

      • Description (string) –

        A friendly, more verbose description of the activity.

      • Cause (string) –

        The reason the activity began.

      • StartTime (datetime) –

        The start time of the activity.

      • EndTime (datetime) –

        The end time of the activity.

      • StatusCode (string) –

        The current status of the activity.

      • StatusMessage (string) –

        A friendly, more verbose description of the activity status.

      • Progress (integer) –

        A value between 0 and 100 that indicates the progress of the activity.

      • Details (string) –

        The details about the activity.

      • AutoScalingGroupState (string) –

        The state of the Auto Scaling group, which is either InService or Deleted.

      • AutoScalingGroupARN (string) –

        The Amazon Resource Name (ARN) of the Auto Scaling group.

Exceptions

Examples

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.

response = client.terminate_instance_in_auto_scaling_group(
    InstanceId='i-93633f9b',
    ShouldDecrementDesiredCapacity=False,
)

print(response)

Expected Output:

{
    'ResponseMetadata': {
        '...': '...',
    },
}