terminateInstanceInAutoScalingGroup method

Future<ActivityType> terminateInstanceInAutoScalingGroup({
  1. required String instanceId,
  2. required bool shouldDecrementDesiredCapacity,
})

Terminates the specified instance and optionally adjusts the desired group size.

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 Rebalancing activities in the Amazon EC2 Auto Scaling User Guide.

May throw ScalingActivityInProgressFault. May throw ResourceContentionFault.

Parameter instanceId : The ID of the instance.

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

Implementation

Future<ActivityType> terminateInstanceInAutoScalingGroup({
  required String instanceId,
  required bool shouldDecrementDesiredCapacity,
}) async {
  ArgumentError.checkNotNull(instanceId, 'instanceId');
  _s.validateStringLength(
    'instanceId',
    instanceId,
    1,
    19,
    isRequired: true,
  );
  ArgumentError.checkNotNull(
      shouldDecrementDesiredCapacity, 'shouldDecrementDesiredCapacity');
  final $request = <String, dynamic>{};
  $request['InstanceId'] = instanceId;
  $request['ShouldDecrementDesiredCapacity'] = shouldDecrementDesiredCapacity;
  final $result = await _protocol.send(
    $request,
    action: 'TerminateInstanceInAutoScalingGroup',
    version: '2011-01-01',
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    shape: shapes['TerminateInstanceInAutoScalingGroupType'],
    shapes: shapes,
    resultWrapper: 'TerminateInstanceInAutoScalingGroupResult',
  );
  return ActivityType.fromXml($result);
}