StopTask
Stops a running task. Any tags associated with the task will be deleted.
When you call StopTask
on a task, the equivalent of docker
stop
is issued to the containers running in the task. This results in a
SIGTERM
value and a default 30-second timeout, after which the
SIGKILL
value is sent and the containers are forcibly stopped. If the
container handles the SIGTERM
value gracefully and exits within 30 seconds
from receiving it, no SIGKILL
value is sent.
For Windows containers, POSIX signals do not work and runtime stops the container by
sending a CTRL_SHUTDOWN_EVENT
. For more information, see Unable to react to graceful shutdown
of (Windows) container #25982
Note
The default 30-second timeout can be configured on the Amazon ECS container agent with
the ECS_CONTAINER_STOP_TIMEOUT
variable. For more information, see
Amazon ECS Container Agent Configuration in the
Amazon Elastic Container Service Developer Guide.
Request Syntax
{
"cluster": "string
",
"reason": "string
",
"task": "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 task to stop. If you do not specify a cluster, the default cluster is assumed.
Type: String
Required: No
- reason
-
An optional message specified when a task is stopped. For example, if you're using a custom scheduler, you can use this parameter to specify the reason for stopping the task here, and the message appears in subsequent DescribeTasks> API operations on this task.
Type: String
Required: No
- task
-
The task ID of the task to stop.
Type: String
Required: Yes
Response Syntax
{
"task": {
"attachments": [
{
"details": [
{
"name": "string",
"value": "string"
}
],
"id": "string",
"status": "string",
"type": "string"
}
],
"attributes": [
{
"name": "string",
"targetId": "string",
"targetType": "string",
"value": "string"
}
],
"availabilityZone": "string",
"capacityProviderName": "string",
"clusterArn": "string",
"connectivity": "string",
"connectivityAt": number,
"containerInstanceArn": "string",
"containers": [
{
"containerArn": "string",
"cpu": "string",
"exitCode": number,
"gpuIds": [ "string" ],
"healthStatus": "string",
"image": "string",
"imageDigest": "string",
"lastStatus": "string",
"managedAgents": [
{
"lastStartedAt": number,
"lastStatus": "string",
"name": "string",
"reason": "string"
}
],
"memory": "string",
"memoryReservation": "string",
"name": "string",
"networkBindings": [
{
"bindIP": "string",
"containerPort": number,
"containerPortRange": "string",
"hostPort": number,
"hostPortRange": "string",
"protocol": "string"
}
],
"networkInterfaces": [
{
"attachmentId": "string",
"ipv6Address": "string",
"privateIpv4Address": "string"
}
],
"reason": "string",
"runtimeId": "string",
"taskArn": "string"
}
],
"cpu": "string",
"createdAt": number,
"desiredStatus": "string",
"enableExecuteCommand": boolean,
"ephemeralStorage": {
"sizeInGiB": number
},
"executionStoppedAt": number,
"fargateEphemeralStorage": {
"kmsKeyId": "string",
"sizeInGiB": number
},
"group": "string",
"healthStatus": "string",
"inferenceAccelerators": [
{
"deviceName": "string",
"deviceType": "string"
}
],
"lastStatus": "string",
"launchType": "string",
"memory": "string",
"overrides": {
"containerOverrides": [
{
"command": [ "string" ],
"cpu": number,
"environment": [
{
"name": "string",
"value": "string"
}
],
"environmentFiles": [
{
"type": "string",
"value": "string"
}
],
"memory": number,
"memoryReservation": number,
"name": "string",
"resourceRequirements": [
{
"type": "string",
"value": "string"
}
]
}
],
"cpu": "string",
"ephemeralStorage": {
"sizeInGiB": number
},
"executionRoleArn": "string",
"inferenceAcceleratorOverrides": [
{
"deviceName": "string",
"deviceType": "string"
}
],
"memory": "string",
"taskRoleArn": "string"
},
"platformFamily": "string",
"platformVersion": "string",
"pullStartedAt": number,
"pullStoppedAt": number,
"startedAt": number,
"startedBy": "string",
"stopCode": "string",
"stoppedAt": number,
"stoppedReason": "string",
"stoppingAt": number,
"tags": [
{
"key": "string",
"value": "string"
}
],
"taskArn": "string",
"taskDefinitionArn": "string",
"version": number
}
}
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.
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 thePROVISIONING
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 AWS Signature Version 4
signature. For more information, 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
create them manually. When you use the AWS Command Line Interface
Example
This example request stops a task with the ID
1dc5c17a-422b-4dc4-b493-371970c6c4d6
in the default
cluster.
Sample Request
POST / HTTP/1.1
Host: ecs.us-east-1.amazonaws.com
Accept-Encoding: identity
Content-Length: 88
X-Amz-Target: AmazonEC2ContainerServiceV20141113.StopTask
X-Amz-Date: 20161121T220318Z
User-Agent: aws-cli/1.11.13 Python/2.7.12 Darwin/16.1.0 botocore/1.4.66
Content-Type: application/x-amz-json-1.1
Authorization: AUTHPARAMS
{
"task": "1dc5c17a-422b-4dc4-b493-371970c6c4d6"
}
Sample Response
HTTP/1.1 200 OK
Server: Server
Date: Mon, 21 Nov 2016 22:03:18 GMT
Content-Type: application/x-amz-json-1.1
Content-Length: 1260
Connection: keep-alive
x-amzn-RequestId: 123a4b56-7c89-01d2-3ef4-example5678f
{
"task": {
"clusterArn": "arn:aws:ecs:us-east-1:012345678910:cluster/default",
"containerInstanceArn": "arn:aws:ecs:us-east-1:012345678910:container-instance/default/5991d8da-1d59-49d2-a31f-4230f9e73140",
"containers": [
{
"containerArn": "arn:aws:ecs:us-east-1:012345678910:container/4df26bb4-f057-467b-a079-961675296e64",
"lastStatus": "RUNNING",
"name": "simple-app",
"networkBindings": [
{
"bindIP": "0.0.0.0",
"containerPort": 80,
"hostPort": 32774,
"protocol": "tcp"
}
],
"taskArn": "arn:aws:ecs:us-east-1:012345678910:task/default/1dc5c17a-422b-4dc4-b493-371970c6c4d6"
},
{
"containerArn": "arn:aws:ecs:us-east-1:012345678910:container/e09064f7-7361-4c87-8ab9-8d073bbdbcb9",
"lastStatus": "RUNNING",
"name": "busybox",
"networkBindings": [],
"taskArn": "arn:aws:ecs:us-east-1:012345678910:task/default/1dc5c17a-422b-4dc4-b493-371970c6c4d6"
}
],
"createdAt": 1476822811.295,
"desiredStatus": "STOPPED",
"lastStatus": "RUNNING",
"overrides": {
"containerOverrides": [
{
"name": "simple-app"
},
{
"name": "busybox"
}
]
},
"startedAt": 1476822833.998,
"startedBy": "ecs-svc/9223370560032507596",
"stoppedReason": "Task stopped by user",
"taskArn": "arn:aws:ecs:us-east-1:012345678910:task/1dc5c17a-422b-4dc4-b493-371970c6c4d6",
"taskDefinitionArn": "arn:aws:ecs:us-east-1:012345678910:task-definition/default/console-sample-app-dynamic-ports:1",
"version": 0
}
}
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: