New user sign up using AWS Builder ID
New user sign up using AWS Builder ID is currently unavailable on re:Post. To sign up, please use the AWS Management Console instead.
How do I resolve errors when I delete a capacity provider in Amazon ECS?
I get an error when I try to delete a capacity provider for my Amazon Elastic Container Service (Amazon ECS) cluster.
Short description
If you used the AWS Command Line Interface (AWS CLI) delete-capacity-provider command or DeleteCapacityProvider API, then you might receive one of the following errors:
"updateStatus": "DELETE_FAILED"
-or-
"updateStatusReason": "The capacity provider cannot be deleted because it is associated with cluster: Cluster Name. Remove the capacity provider from the cluster and try again."
If you used the AWS Management Console to delete a capacity provider, then you might receive the following error:
"There was an error deleting capacity provider Capacity Provider Name. The specified capacity provider is in use and cannot be removed"
You can't delete a capacity provider that's associated with a cluster. To resolve deletion issues, you must either remove the capacity provider from the cluster or delete the cluster. Then, delete the capacity provider.
Note: If you delete an Amazon EC2 Auto Scaling group, then the related capacity provider enters the INACTIVE state. It's not a best practice to use capacity providers in the INACTIVE state because they might be automatically removed at any time.
Resolution
Note: If you receive errors when you run AWS CLI commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version. For formatting, install jq from Download jq on the jq website.
Identify the capacity providers that are associated with your cluster
To identify all capacity providers that are associated with an Amazon ECS cluster, use the Amazon ECS console or the AWS CLI.
Amazon ECS console
Complete the following steps:
- Open the Amazon ECS console.
- In the navigation pane, choose Clusters.
- Select your cluster.
- Choose the Infrastructure tab.
- Choose Capacity providers.
AWS CLI
Run the following describe-clusters command:
aws ecs describe-clusters --cluster your-cluster-name | jq '.clusters[].capacityProviders'
Note: Replace your-cluster-name with your cluster name.
Make sure that Amazon ECS isn't using the capacity provider in the capacity provider strategy
To view the services that use the capacity provider, run the following script:
#!/bin/bash cluster=ClusterName capacityprovider=CapacityProviderName services=$(aws ecs list-services --cluster ${cluster} | jq --raw-output '.serviceArns[]') aws ecs describe-services \ --cluster ${cluster} \ --services ${services} \ | jq -r --arg capacityprovider "${capacityprovider}" \ '.services[] | select(.capacityProviderStrategy[]?.capacityProvider == $capacityprovider) | .serviceName'
Note: Replace ClusterName with your cluster name and CapacityProviderName with your capacity provider name. If the script returns a blank output, then none of the services in the cluster are using the capacity provider. In this case, proceed to the Check whether your capacity provider is set in the default capacity provider strategy for the cluster section.
Before you can delete an existing capacity provider that's in use, you must update Amazon ECS to use a new capacity provider. Use the Amazon ECS console or the AWS CLI. When you update the service, use Force new deployment to transition tasks that use Amazon Elastic Compute Cloud (Amazon EC2) instance capacity between providers.
To use the AWS CLI to update the capacity provider, complete the following steps:
-
Run the following describe-services command to view the existing capacity provider strategy for the service:
aws ecs describe-services --cluster my-cluster --services my-service
Note: Replace my-cluster with your cluster name and my-service with your service name.
-
Create a new capacity provider strategy that excludes the capacity provider that you want to remove. Make sure that the total weight for the remaining capacity providers is 100.
-
Run the following update-service command to update the service:
aws ecs update-service \ --cluster your-cluster-name \ --service your-service-name \ --capacity-provider-strategy capacityProvider=remaining-provider,weight=100 \ --force-new-deployment
Note: Replace your-cluster-name with your cluster name and your-service-name with your service name. Also, replace remaining-provider with the name of the new capacity provider.
Check whether the capacity provider is set in the default strategy for the cluster
To find the default capacity provider strategy for your cluster, run the following describe-clusters command:
aws ecs describe-clusters --cluster mycluster | jq '.clusters[].defaultCapacityProviderStrategy'
If the capacity provider that you want to delete is in the command's output, then you must modify the default capacity provider strategy. You can use the Amazon ECS console or the AWS CLI.
Amazon ECS console
Complete the following steps:
- Open the Amazon ECS console.
- In the navigation pane, choose Clusters.
- Select your cluster.
- Choose Update cluster.
- Under Cluster configuration, for Default capacity provider strategy, choose Remove for the capacity provider.
- Choose Update.
AWS CLI
Run the following put-cluster-capacity-providers command:
aws ecs put-cluster-capacity-providers --cluster ClusterName --capacity-providers [] --default-capacity-provider-strategy []
Note: Replace ClusterName with your cluster name.
Replace the previous capacity provider with a new capacity provider before you delete it. To replace the capacity provider, run the following put-cluster-capacity-provider command:
aws ecs put-cluster-capacity-providers --cluster ClusterName --capacity-providers UpdatedCapacityProvider --default-capacity-provider-strategy capacityProvider=UpdatedCapacityProvider --region RegionName
Note: Replace ClusterName with your cluster name, UpdatedCapacityProvider with the new capacity provider, and RegionName with your AWS Region.
When you run the put-cluster-capacity-providers command, you must include all capacity providers that you want to keep in the cluster. If you don't include a capacity provider, then Amazon ECS disassociates the capacity provider from the cluster.
Delete the capacity provider
To delete the capacity provider, run the following delete-capacity-provider command:
aws ecs delete-capacity-provider --capacity-provider PreviousCapacityProvider
Note: Replace PreviousCapacityProvider with the ARN of the capacity provider that you want to delete.
To verify that the capacity provider is deleted, run the following describe-capacity-providers command:
aws ecs describe-capacity-providers --capacity-provider PreviousCapacityProvider
Note: Replace PreviousCapacityProvider with the ARN of the capacity provider that you deleted.
In the command's output, verify that the status for the capacity provider is INACTIVE.

Relevant content
- asked 10 days agolg...
- Accepted Answerasked 3 years agolg...
- asked 9 months agolg...
- asked a year agolg...
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 22 days ago
- AWS OFFICIALUpdated 6 months ago