DeleteService
Deletes a specified service within a cluster. You can delete a service if you have no running tasks in it and the desired task count is zero. If the service is actively maintaining tasks, you can't delete it, and you must update the service to a desired task count of zero. For more information, see UpdateService.
Note
When you delete a service, if there are still running tasks that require cleanup, the service
status moves from ACTIVE
to DRAINING
, and the service is no longer
visible in the console or in the ListServices API operation.
After all tasks have transitioned to either STOPPING
or STOPPED
status,
the service status moves from DRAINING
to INACTIVE
. Services in the
DRAINING
or INACTIVE
status can still be viewed with the DescribeServices API operation. However, in the future, INACTIVE
services
may be cleaned up and purged from Amazon ECS record keeping, and DescribeServices calls on
those services return a ServiceNotFoundException
error.
Important
If you attempt to create a new service with the same name as an existing service in either
ACTIVE
or DRAINING
status, you receive an error.
Request Syntax
{
"cluster": "string
",
"force": boolean
,
"service": "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 service to delete. If you do not specify a cluster, the default cluster is assumed.
Type: String
Required: No
- force
-
If
true
, allows you to delete a service even if it wasn't scaled down to zero tasks. It's only necessary to use this if the service uses theREPLICA
scheduling strategy.Type: Boolean
Required: No
- service
-
The name of the service to delete.
Type: String
Required: Yes
Response Syntax
{
"service": {
"availabilityZoneRebalancing": "string",
"capacityProviderStrategy": [
{
"base": number,
"capacityProvider": "string",
"weight": number
}
],
"clusterArn": "string",
"createdAt": number,
"createdBy": "string",
"deploymentConfiguration": {
"alarms": {
"alarmNames": [ "string" ],
"enable": boolean,
"rollback": boolean
},
"deploymentCircuitBreaker": {
"enable": boolean,
"rollback": boolean
},
"maximumPercent": number,
"minimumHealthyPercent": number
},
"deploymentController": {
"type": "string"
},
"deployments": [
{
"capacityProviderStrategy": [
{
"base": number,
"capacityProvider": "string",
"weight": number
}
],
"createdAt": number,
"desiredCount": number,
"failedTasks": number,
"fargateEphemeralStorage": {
"kmsKeyId": "string"
},
"id": "string",
"launchType": "string",
"networkConfiguration": {
"awsvpcConfiguration": {
"assignPublicIp": "string",
"securityGroups": [ "string" ],
"subnets": [ "string" ]
}
},
"pendingCount": number,
"platformFamily": "string",
"platformVersion": "string",
"rolloutState": "string",
"rolloutStateReason": "string",
"runningCount": number,
"serviceConnectConfiguration": {
"enabled": boolean,
"logConfiguration": {
"logDriver": "string",
"options": {
"string" : "string"
},
"secretOptions": [
{
"name": "string",
"valueFrom": "string"
}
]
},
"namespace": "string",
"services": [
{
"clientAliases": [
{
"dnsName": "string",
"port": number
}
],
"discoveryName": "string",
"ingressPortOverride": number,
"portName": "string",
"timeout": {
"idleTimeoutSeconds": number,
"perRequestTimeoutSeconds": number
},
"tls": {
"issuerCertificateAuthority": {
"awsPcaAuthorityArn": "string"
},
"kmsKey": "string",
"roleArn": "string"
}
}
]
},
"serviceConnectResources": [
{
"discoveryArn": "string",
"discoveryName": "string"
}
],
"status": "string",
"taskDefinition": "string",
"updatedAt": number,
"volumeConfigurations": [
{
"managedEBSVolume": {
"encrypted": boolean,
"filesystemType": "string",
"iops": number,
"kmsKeyId": "string",
"roleArn": "string",
"sizeInGiB": number,
"snapshotId": "string",
"tagSpecifications": [
{
"propagateTags": "string",
"resourceType": "string",
"tags": [
{
"key": "string",
"value": "string"
}
]
}
],
"throughput": number,
"volumeType": "string"
},
"name": "string"
}
],
"vpcLatticeConfigurations": [
{
"portName": "string",
"roleArn": "string",
"targetGroupArn": "string"
}
]
}
],
"desiredCount": number,
"enableECSManagedTags": boolean,
"enableExecuteCommand": boolean,
"events": [
{
"createdAt": number,
"id": "string",
"message": "string"
}
],
"healthCheckGracePeriodSeconds": number,
"launchType": "string",
"loadBalancers": [
{
"containerName": "string",
"containerPort": number,
"loadBalancerName": "string",
"targetGroupArn": "string"
}
],
"networkConfiguration": {
"awsvpcConfiguration": {
"assignPublicIp": "string",
"securityGroups": [ "string" ],
"subnets": [ "string" ]
}
},
"pendingCount": number,
"placementConstraints": [
{
"expression": "string",
"type": "string"
}
],
"placementStrategy": [
{
"field": "string",
"type": "string"
}
],
"platformFamily": "string",
"platformVersion": "string",
"propagateTags": "string",
"roleArn": "string",
"runningCount": number,
"schedulingStrategy": "string",
"serviceArn": "string",
"serviceName": "string",
"serviceRegistries": [
{
"containerName": "string",
"containerPort": number,
"port": number,
"registryArn": "string"
}
],
"status": "string",
"tags": [
{
"key": "string",
"value": "string"
}
],
"taskDefinition": "string",
"taskSets": [
{
"capacityProviderStrategy": [
{
"base": number,
"capacityProvider": "string",
"weight": number
}
],
"clusterArn": "string",
"computedDesiredCount": number,
"createdAt": number,
"externalId": "string",
"fargateEphemeralStorage": {
"kmsKeyId": "string"
},
"id": "string",
"launchType": "string",
"loadBalancers": [
{
"containerName": "string",
"containerPort": number,
"loadBalancerName": "string",
"targetGroupArn": "string"
}
],
"networkConfiguration": {
"awsvpcConfiguration": {
"assignPublicIp": "string",
"securityGroups": [ "string" ],
"subnets": [ "string" ]
}
},
"pendingCount": number,
"platformFamily": "string",
"platformVersion": "string",
"runningCount": number,
"scale": {
"unit": "string",
"value": number
},
"serviceArn": "string",
"serviceRegistries": [
{
"containerName": "string",
"containerPort": number,
"port": number,
"registryArn": "string"
}
],
"stabilityStatus": "string",
"stabilityStatusAt": number,
"startedBy": "string",
"status": "string",
"tags": [
{
"key": "string",
"value": "string"
}
],
"taskDefinition": "string",
"taskSetArn": "string",
"updatedAt": 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
- ServiceNotFoundException
-
The specified service wasn't found. You can view your available services with ListServices. Amazon ECS services are cluster specific and Region specific.
HTTP Status Code: 400
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 API request deletes the test
service from the default
cluster.
Sample Request
POST / HTTP/1.1
Host: ecs.us-east-1.amazonaws.com
Accept-Encoding: identity
Content-Length: 19
X-Amz-Target: AmazonEC2ContainerServiceV20141113.DeleteService
X-Amz-Date: 20150429T172539Z
Content-Type: application/x-amz-json-1.1
Authorization: AUTHPARAMS
{
"service": "test"
}
Sample Response
HTTP/1.1 200 OK
Server: Server
Date: Wed, 29 Apr 2015 17:25:40 GMT
Content-Type: application/x-amz-json-1.1
Content-Length: 13590
Connection: keep-alive
x-amzn-RequestId: 123a4b56-7c89-01d2-3ef4-example5678f
{
"service": {
"clusterArn": "arn:aws:ecs:us-east-1:012345678910:cluster/default",
"deploymentConfiguration": {
"maximumPercent": 200,
"minimumHealthyPercent": 100
},
"deployments": [
{
"createdAt": 1430320735.285,
"desiredCount": 0,
"id": "ecs-svc/9223370606534040511",
"pendingCount": 0,
"runningCount": 0,
"status": "PRIMARY",
"taskDefinition": "arn:aws:ecs:us-east-1:012345678910:task-definition/sleep360:27",
"updatedAt": 1430320735.285
}
],
"desiredCount": 0,
"events": [],
"loadBalancers": [],
"pendingCount": 0,
"runningCount": 0,
"serviceArn": "arn:aws:ecs:us-east-1:012345678910:service/default/test",
"serviceName": "test",
"status": "DRAINING",
"taskDefinition": "arn:aws:ecs:us-east-1:012345678910:task-definition/sleep360:27"
}
}
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: