Amazon EC2 Container Service
API Reference (API Version 2014-11-13)


Modifies the status of an Amazon ECS container instance.

You can change the status of a container instance to DRAINING to manually remove an instance from a cluster, for example to perform system updates, update the Docker daemon, or scale down the cluster size.

When you set a container instance to DRAINING, Amazon ECS prevents new tasks from being scheduled for placement on the container instance and replacement service tasks are started on other container instances in the cluster if the resources are available. Service tasks on the container instance that are in the PENDING state are stopped immediately.

Service tasks on the container instance that are in the RUNNING state are stopped and replaced according the service's deployment configuration parameters, minimumHealthyPercent and maximumPercent. Note that you can change the deployment configuration of your service using UpdateService.

  • If minimumHealthyPercent is below 100%, the scheduler can ignore desiredCount temporarily during task replacement. For example, desiredCount is four tasks, a minimum of 50% allows the scheduler to stop two existing tasks before starting two new tasks. If the minimum is 100%, the service scheduler can't remove existing tasks until the replacement tasks are considered healthy. Tasks for services that do not use a load balancer are considered healthy if they are in the RUNNING state. Tasks for services that use a load balancer are considered healthy if they are in the RUNNING state and the container instance they are hosted on is reported as healthy by the load balancer.

  • The maximumPercent parameter represents an upper limit on the number of running tasks during task replacement, which enables you to define the replacement batch size. For example, if desiredCount of four tasks, a maximum of 200% starts four new tasks before stopping the four tasks to be drained (provided that the cluster resources required to do this are available). If the maximum is 100%, then replacement tasks can't start until the draining tasks have stopped.

Any PENDING or RUNNING tasks that do not belong to a service are not affected; you must wait for them to finish or stop them manually.

A container instance has completed draining when it has no more RUNNING tasks. You can verify this using ListTasks.

When you set a container instance to ACTIVE, the Amazon ECS scheduler can begin scheduling tasks on the instance again.

Request Syntax

Copy to clipboard
{ "cluster": "string", "containerInstances": [ "string" ], "status": "string" }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.


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

Type: String

Required: No


A list of container instance IDs or full Amazon Resource Name (ARN) entries.

Type: array of Strings

Required: Yes


The container instance state with which to update the container instance.

Type: String


Required: Yes

Response Syntax

Copy to clipboard
{ "containerInstances": [ { "agentConnected": boolean, "agentUpdateStatus": "string", "attributes": [ { "name": "string", "targetId": "string", "targetType": "string", "value": "string" } ], "containerInstanceArn": "string", "ec2InstanceId": "string", "pendingTasksCount": number, "registeredResources": [ { "doubleValue": number, "integerValue": number, "longValue": number, "name": "string", "stringSetValue": [ "string" ], "type": "string" } ], "remainingResources": [ { "doubleValue": number, "integerValue": number, "longValue": number, "name": "string", "stringSetValue": [ "string" ], "type": "string" } ], "runningTasksCount": number, "status": "string", "version": number, "versionInfo": { "agentHash": "string", "agentVersion": "string", "dockerVersion": "string" } } ], "failures": [ { "arn": "string", "reason": "string" } ] }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.


The list of container instances.

Type: array of ContainerInstance objects


Any failures associated with the call.

Type: array of Failure objects


For information about the errors that are common to all actions, see Common Errors.


These errors are usually caused by a client action, such as using an action or resource on behalf of a user that doesn't have permission to use the action or resource, or specifying an identifier that is not valid.

HTTP Status Code: 400


The specified cluster could not be found. You can view your available clusters with ListClusters. Amazon ECS clusters are region-specific.

HTTP Status Code: 400


The specified parameter is invalid. Review the available parameters for the API request.

HTTP Status Code: 400


These errors are usually caused by a server issue.

HTTP Status Code: 500


In the following example or examples, the Authorization header contents (AUTHPARAMS) must be replaced with an AWS Signature Version 4 signature. For more information about creating these signatures, see Signature Version 4 Signing Process in the AWS General Reference.

You only need to learn how to sign HTTP requests if you intend to manually create them. When you use the AWS Command Line Interface (AWS CLI) or one of the AWS SDKs to make requests to AWS, these tools automatically sign the requests for you with the access key that you specify when you configure the tools. When you use these tools, you don't need to learn how to sign requests yourself.


This example sets a container instance in the default cluster with the ID 1c3be8ed-df30-47b4-8f1e-6e68ebd01f34 to the DRAINING status so that it can not receive tasks for placement.

Sample Request

Copy to clipboard
POST / HTTP/1.1 Host: Accept-Encoding: identity Content-Length: 114 X-Amz-Target: AmazonEC2ContainerServiceV20141113.UpdateContainerInstancesState X-Amz-Date: 20161220T221142Z User-Agent: aws-cli/1.11.31 Python/2.7.12 Darwin/16.3.0 botocore/1.4.88 Content-Type: application/x-amz-json-1.1 Authorization: AUTHPARAMS { "status": "DRAINING", "cluster": "default", "containerInstances": [ "1c3be8ed-df30-47b4-8f1e-6e68ebd01f34" ] }

Sample Response

Copy to clipboard
HTTP/1.1 200 OK Server: Server Date: Tue, 20 Dec 2016 22:11:42 GMT Content-Type: application/x-amz-json-1.1 Content-Length: 2344 Connection: keep-alive x-amzn-RequestId: 49d68928-c701-11e6-8f99-6103d648cdad { "containerInstances": [ { "agentConnected": true, "attributes": [ { "name": "ecs.availability-zone", "value": "us-west-2b" }, { "name": "com.amazonaws.ecs.capability.logging-driver.syslog" }, { "name": "ecs.instance-type", "value": "c4.xlarge" }, { "name": "ecs.ami-id", "value": "ami-a2ca61c2" }, { "name": "com.amazonaws.ecs.capability.task-iam-role-network-host" }, { "name": "com.amazonaws.ecs.capability.logging-driver.awslogs" }, { "name": "com.amazonaws.ecs.capability.logging-driver.json-file" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17" }, { "name": "com.amazonaws.ecs.capability.privileged-container" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19" }, { "name": "com.amazonaws.ecs.capability.ecr-auth" }, { "name": "ecs.os-type", "value": "linux" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.20" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.22" }, { "name": "com.amazonaws.ecs.capability.task-iam-role" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.23" } ], "containerInstanceArn": "arn:aws:ecs:us-west-2:012345678910:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "ec2InstanceId": "i-05d99c76955727ec6", "pendingTasksCount": 0, "registeredResources": [ { "doubleValue": 0, "integerValue": 4096, "longValue": 0, "name": "CPU", "type": "INTEGER" }, { "doubleValue": 0, "integerValue": 7482, "longValue": 0, "name": "MEMORY", "type": "INTEGER" }, { "doubleValue": 0, "integerValue": 0, "longValue": 0, "name": "PORTS", "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ], "type": "STRINGSET" }, { "doubleValue": 0, "integerValue": 0, "longValue": 0, "name": "PORTS_UDP", "stringSetValue": [], "type": "STRINGSET" } ], "remainingResources": [ { "doubleValue": 0, "integerValue": 4096, "longValue": 0, "name": "CPU", "type": "INTEGER" }, { "doubleValue": 0, "integerValue": 7482, "longValue": 0, "name": "MEMORY", "type": "INTEGER" }, { "doubleValue": 0, "integerValue": 0, "longValue": 0, "name": "PORTS", "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ], "type": "STRINGSET" }, { "doubleValue": 0, "integerValue": 0, "longValue": 0, "name": "PORTS_UDP", "stringSetValue": [], "type": "STRINGSET" } ], "runningTasksCount": 0, "status": "DRAINING", "version": 30, "versionInfo": { "agentHash": "efe53c6", "agentVersion": "1.13.1", "dockerVersion": "DockerVersion: 1.11.2" } } ], "failures": [] }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: