UpdateContainerInstancesState - Amazon Elastic Container Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

UpdateContainerInstancesState

Modifies the status of an Amazon ECS container instance.

Once a container instance has reached an ACTIVE state, 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.

Important

A container instance can't be changed to DRAINING until it has reached an ACTIVE status. If the instance is in any other status, an error will be received.

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 to the service's deployment configuration parameters, minimumHealthyPercent and maximumPercent. 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're in the RUNNING state. Tasks for services that use a load balancer are considered healthy if they're in the RUNNING state and are reported as healthy by the load balancer.

  • The maximumPercent parameter represents an upper limit on the number of running tasks during task replacement. You can use this to define the replacement batch size. For example, if desiredCount is 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 aren't 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 a container instance has been drained, you can set a container instance to ACTIVE status and once it has reached that status the Amazon ECS scheduler can begin scheduling tasks on the instance again.

Request Syntax

{ "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.

cluster

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

containerInstances

A list of up to 10 container instance IDs or full ARN entries.

Type: Array of strings

Required: Yes

status

The container instance state to update the container instance with. The only valid values for this action are ACTIVE and DRAINING. A container instance can only be updated to DRAINING status once it has reached an ACTIVE state. If a container instance is in REGISTERING, DEREGISTERING, or REGISTRATION_FAILED state you can describe the container instance but can't update the container instance state.

Type: String

Valid Values: ACTIVE | DRAINING | REGISTERING | DEREGISTERING | REGISTRATION_FAILED

Required: Yes

Response Syntax

{ "containerInstances": [ { "agentConnected": boolean, "agentUpdateStatus": "string", "attachments": [ { "details": [ { "name": "string", "value": "string" } ], "id": "string", "status": "string", "type": "string" } ], "attributes": [ { "name": "string", "targetId": "string", "targetType": "string", "value": "string" } ], "capacityProviderName": "string", "containerInstanceArn": "string", "ec2InstanceId": "string", "healthStatus": { "details": [ { "lastStatusChange": number, "lastUpdated": number, "status": "string", "type": "string" } ], "overallStatus": "string" }, "pendingTasksCount": number, "registeredAt": 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", "statusReason": "string", "tags": [ { "key": "string", "value": "string" } ], "version": number, "versionInfo": { "agentHash": "string", "agentVersion": "string", "dockerVersion": "string" } } ], "failures": [ { "arn": "string", "detail": "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.

containerInstances

The list of container instances.

Type: Array of ContainerInstance objects

failures

Any failures associated with the call.

Type: Array of Failure objects

Errors

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

ClientException

These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.

The following list includes additional causes for the error:

  • The RunTask could not be processed because you use managed scaling and there is a capacity error because the quota of tasks in the PROVISIONING per cluster has been reached. For information about the service quotas, see Amazon ECS service quotas.

HTTP Status Code: 400

ClusterNotFoundException

The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.

HTTP Status Code: 400

InvalidParameterException

The specified parameter isn't valid. Review the available parameters for the API request.

HTTP Status Code: 400

ServerException

These errors are usually caused by a server issue.

HTTP Status Code: 500

Examples

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

You only need to learn how to sign HTTP requests if you intend to create them manually. When you use the Amazon Command Line Interface or one of the Amazon SDKs to make requests to Amazon, 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 have to sign requests yourself.

Example

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't receive tasks for placement.

Sample Request

POST / HTTP/1.1 Host: ecs.us-west-2.amazonaws.com 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

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/default/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 Amazon SDKs, see the following: