deregisterContainerInstance method

Future<DeregisterContainerInstanceResponse> deregisterContainerInstance({
  1. required String containerInstance,
  2. String? cluster,
  3. bool? force,
})

Deregisters an Amazon ECS container instance from the specified cluster. This instance is no longer available to run tasks.

If you intend to use the container instance for some other purpose after deregistration, you should stop all of the tasks running on the container instance before deregistration. That prevents any orphaned tasks from consuming resources.

Deregistering a container instance removes the instance from a cluster, but it does not terminate the EC2 instance. If you are finished using the instance, be sure to terminate it in the Amazon EC2 console to stop billing.

May throw ServerException. May throw ClientException. May throw InvalidParameterException. May throw ClusterNotFoundException.

Parameter containerInstance : The container instance ID or full ARN of the container instance to deregister. The ARN contains the arn:aws:ecs namespace, followed by the Region of the container instance, the AWS account ID of the container instance owner, the container-instance namespace, and then the container instance ID. For example, arn:aws:ecs:region:aws_account_id:container-instance/container_instance_ID.

Parameter cluster : The short name or full Amazon Resource Name (ARN) of the cluster that hosts the container instance to deregister. If you do not specify a cluster, the default cluster is assumed.

Parameter force : Forces the deregistration of the container instance. If you have tasks running on the container instance when you deregister it with the force option, these tasks remain running until you terminate the instance or the tasks stop through some other means, but they are orphaned (no longer monitored or accounted for by Amazon ECS). If an orphaned task on your container instance is part of an Amazon ECS service, then the service scheduler starts another copy of that task, on a different container instance if possible.

Any containers in orphaned service tasks that are registered with a Classic Load Balancer or an Application Load Balancer target group are deregistered. They begin connection draining according to the settings on the load balancer or target group.

Implementation

Future<DeregisterContainerInstanceResponse> deregisterContainerInstance({
  required String containerInstance,
  String? cluster,
  bool? force,
}) async {
  ArgumentError.checkNotNull(containerInstance, 'containerInstance');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target':
        'AmazonEC2ContainerServiceV20141113.DeregisterContainerInstance'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'containerInstance': containerInstance,
      if (cluster != null) 'cluster': cluster,
      if (force != null) 'force': force,
    },
  );

  return DeregisterContainerInstanceResponse.fromJson(jsonResponse.body);
}