detachInstances method

Future<DetachInstancesAnswer> detachInstances({
  1. required String autoScalingGroupName,
  2. required bool shouldDecrementDesiredCapacity,
  3. List<String>? instanceIds,
})

Removes one or more instances from the specified Auto Scaling group.

After the instances are detached, you can manage them independent of the Auto Scaling group.

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

If there is a Classic Load Balancer attached to the Auto Scaling group, the instances are deregistered from the load balancer. If there are target groups attached to the Auto Scaling group, the instances are deregistered from the target groups.

For more information, see Detach EC2 instances from your Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.

May throw ResourceContentionFault.

Parameter autoScalingGroupName : The name of the Auto Scaling group.

Parameter shouldDecrementDesiredCapacity : Indicates whether the Auto Scaling group decrements the desired capacity value by the number of instances detached.

Parameter instanceIds : The IDs of the instances. You can specify up to 20 instances.

Implementation

Future<DetachInstancesAnswer> detachInstances({
  required String autoScalingGroupName,
  required bool shouldDecrementDesiredCapacity,
  List<String>? instanceIds,
}) async {
  ArgumentError.checkNotNull(autoScalingGroupName, 'autoScalingGroupName');
  _s.validateStringLength(
    'autoScalingGroupName',
    autoScalingGroupName,
    1,
    255,
    isRequired: true,
  );
  ArgumentError.checkNotNull(
      shouldDecrementDesiredCapacity, 'shouldDecrementDesiredCapacity');
  final $request = <String, dynamic>{};
  $request['AutoScalingGroupName'] = autoScalingGroupName;
  $request['ShouldDecrementDesiredCapacity'] = shouldDecrementDesiredCapacity;
  instanceIds?.also((arg) => $request['InstanceIds'] = arg);
  final $result = await _protocol.send(
    $request,
    action: 'DetachInstances',
    version: '2011-01-01',
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    shape: shapes['DetachInstancesQuery'],
    shapes: shapes,
    resultWrapper: 'DetachInstancesResult',
  );
  return DetachInstancesAnswer.fromXml($result);
}