Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-ecs): can't update ECS cluster because of "capacity provider is in use"

See original GitHub issue

A previously (before 1.108.0) created ECS cluster with FARGATE and FARGATE_SPOT capacity providers can’t be updated anymore because of this error:

Error occurred during operation 'putClusterCapacityProviders SDK error: The specified capacity provider is in use and cannot be removed.

Reproduction Steps

Create an ECS cluster with

capacityProviders: ["FARGATE", "FARGATE_SPOT"],

with a CDK version prior to 1.108.0

Then upgrade CDK to latest version (1.110.1), try to update the stack to

enableFargateCapacityProviders: true,

(because the old property is deprecated)

What did you expect to happen?

Capacity providers should be set correctly and cluster should be updated

What actually happened?

Resource handler returned message: “Error occurred during operation ‘putClusterCapacityProviders SDK error: The specified capacity provider is in use and cannot be removed. (Service: AmazonECS; Status Code: 400; Error Code: ResourceInUseException; Request ID: ee1d2754-517d-4148-bbb1-25d0f8a1aa88; Proxy: null)’.” (RequestToken: 3d87b953-a468-bffc-d442-862a457b1f9b, HandlerErrorCode: GeneralServiceException)


  • CDK CLI Version : 1.110.1
  • Framework Version: 1.110.1
  • Node.js Version: v14.17.0
  • OS : MacOS 11.4
  • Language (Version): Typescript 4.1.2


Probably caused by

This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

madeline-kcommented, Aug 24, 2021

The issue was introduced with this bug fix:

Unfortunately, we are now between a rock and a hard place, because if we just revert that change, customers who have deployed with 1.108.0 and up could run into this same issue.

In the meantime you can apply this workaround to your cluster. This is the best I could come up with, there might be a simpler way.

import * as cdk from '@aws-cdk/core';
import * as ecs from '@aws-cdk/aws-ecs';

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const cluster = new ecs.Cluster(this, 'MyCluster', {
      enableFargateCapacityProviders: true,

    // Add back the old method of specifying capacity providers
    const cfnCluster = cluster.node.defaultChild as ecs.CfnCluster;
    cfnCluster.capacityProviders = ['FARGATE', 'FARGATE_SPOT'];

    // Remove the new method of specifying capacity providers. 
    cdk.Aspects.of(this).add(new MyAspect());

class MyAspect implements cdk.IAspect {
  public visit(node: cdk.IConstruct): void {
    if (node instanceof ecs.CfnClusterCapacityProviderAssociations) {
      // IMPORTANT: The id supplied here must be the same as the id of your cluster. Don't worry, you won't remove the cluster.  

Note that a simple cluster.node.tryRemoveChild('MyCluster') doesn’t work here, which is why I used an Aspect to remove the CfnClusterCapacityProviderAssociations resource. I am not sure exactly why this is. I think it could be because the resource was added with an Aspect here.

madeline-kcommented, Jul 13, 2021

Looks like this is a breaking change and we should try to fix this as soon as possible. I am going to try to repro it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve capacity provider errors in Amazon ECS
In this scenario, you receive this error message: "The specified capacity provider is in use and cannot be removed" in the console. You...
Read more >
delete-capacity-provider — AWS CLI 2.9.3 Command Reference
When updating a service, the forceNewDeployment option can be used to ensure that any tasks using the Amazon EC2 instance capacity provided by...
Read more >
Cannot delete capcity provider - Stack Overflow
The capacity provider cannot be deleted because it is associated with cluster: my-cluster. Remove the capacity provider from the cluster and ...
Read more >
AWS ECS CapacityProvider not running tasks
That capacity provider was set up with an EC2 auto-scaling group that has an AWS ECS AMI. When I add a task to...
Read more >
AWS re:Invent 2019 New Launch Feature Amazon ECS ...
Now with the layer of Capacity Provider, you can easily connect the two layers of ECS Cluster and ECS Service dynamically, making the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found