Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-ecs): Can't enable both Fargate and ASG capacity providers #14730

Closed
hnrc opened this issue May 17, 2021 · 2 comments · Fixed by #15012
Closed

(aws-ecs): Can't enable both Fargate and ASG capacity providers #14730

hnrc opened this issue May 17, 2021 · 2 comments · Fixed by #15012
Assignees
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. p2

Comments

@hnrc
Copy link

hnrc commented May 17, 2021

According to the ECS Cluster Capacity Providers docs it should be possible to have both Fargate and ASG powered capacity providers associated with a ECS cluster.

A cluster may contain a mix of both Auto Scaling group capacity providers and Fargate capacity providers, however a capacity provider strategy may only contain one or the other but not both.

This seem to not be the case with CDK. Cloudformation fails with a "The cluster already contains capacity provider associations" message when trying to provision a cluster that have both enableFargateCapacityProviders set to true and an ASG provided through addAsgCapacityProvider(...).

Reproduction Steps

const cluster = new Cluster(this, 'EcsCluster', {
  vpc,
  clusterName: props.clusterName,
  enableFargateCapacityProviders: true,
});

const autoScalingGroup = new AutoScalingGroup(this, 'Asg', {
  vpc,
  machineImage: EcsOptimizedImage.amazonLinux2(),
  instanceType: new InstanceType('t3.micro'),
  minCapacity: 1,
  maxCapacity: 100,
});

const capacityProvider = new AsgCapacityProvider(
  this,
  'AsgCapacityProvider',
  {
    autoScalingGroup,
    capacityProviderName: props.clusterName,
  },
);
cluster.addAsgCapacityProvider(capacityProvider);

What did you expect to happen?

The CF stack to finish successfully and for the cluster to be associated with both Fargate and ASG capacity providers, thus allowing for a service to decide if it should run on EC2 or Fargate, in the same ECS cluster.

What actually happened?

Resource handler returned message: "The cluster already contains capacity provider associations" (RequestToken: 5c5f5982-c7d4-37ae-535a-92833ee7bef6, HandlerErrorCode: AlreadyExists)

Environment

  • CDK CLI Version: 1.104.0
  • Framework Version: 1.104.0
  • Node.js Version: 14.16.1
  • OS: MacOS 10.15.7
  • Language (Version): Typescript 4.2.4

This is 🐛 Bug Report

@hnrc hnrc added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 17, 2021
@peterwoodworth peterwoodworth added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label May 17, 2021
@SoManyHs SoManyHs added needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jun 1, 2021
@SoManyHs SoManyHs removed the needs-reproduction This issue needs reproduction. label Jun 2, 2021
@SoManyHs
Copy link
Contributor

SoManyHs commented Jun 3, 2021

The issue here is that we are specifying the FARGATE and FARGATE_SPOT capacity providers as a member of the Cluster resource, but creating ClusterCapacityProviderAssociations for the ASG capacity providers. In order for this to work with cloudformation, all of the capacity providers need to be specified either in the Cluster.CapacityProviders field OR on the ClusterCapacityProviderAssocitations.CapacityProvider field. Since specifying an ASG Capacity Provider in CFN requires specifying the latter in order to avoid a circular dependency issue, we need to change the Fargate CPs to also create a ClusterCPAssociation. Working on a fix!

SoManyHs added a commit to SoManyHs/aws-cdk that referenced this issue Jun 4, 2021
Previously, adding/enabling Fargate capacity providers would add the
FARGATE and FARGATE_SPOT capacity providers a part of the
[capacityProviders
field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders)
on the ECS::Cluster resource. However, ASG Capacity Providers can only
be specified as part of the [capacityProviders field on the
ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of
type must all be specified *either* on the cluster *or* as a
ClusterCapacityProviderAssociation. Therefore, in order to support both types on the same
cluster, Fargate capacity providers must also be specified as a
ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster
resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.
SoManyHs added a commit to SoManyHs/aws-cdk that referenced this issue Jun 8, 2021
Previously, adding/enabling Fargate capacity providers would add the
FARGATE and FARGATE_SPOT capacity providers a part of the
[capacityProviders
field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders)
on the ECS::Cluster resource. However, ASG Capacity Providers can only
be specified as part of the [capacityProviders field on the
ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of
type must all be specified *either* on the cluster *or* as a
ClusterCapacityProviderAssociation. Therefore, in order to support both types on the same
cluster, Fargate capacity providers must also be specified as a
ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster
resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.
SoManyHs added a commit to SoManyHs/aws-cdk that referenced this issue Jun 8, 2021
Previously, adding/enabling Fargate capacity providers would add the
FARGATE and FARGATE_SPOT capacity providers a part of the
[capacityProviders
field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders)
on the ECS::Cluster resource. However, ASG Capacity Providers can only
be specified as part of the [capacityProviders field on the
ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of
type must all be specified *either* on the cluster *or* as a
ClusterCapacityProviderAssociation. Therefore, in order to support both types on the same
cluster, Fargate capacity providers must also be specified as a
ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster
resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.
SoManyHs added a commit to SoManyHs/aws-cdk that referenced this issue Jun 8, 2021
Previously, adding/enabling Fargate capacity providers would add the
FARGATE and FARGATE_SPOT capacity providers a part of the
[capacityProviders
field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders)
on the ECS::Cluster resource. However, ASG Capacity Providers can only
be specified as part of the [capacityProviders field on the
ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of
type must all be specified *either* on the cluster *or* as a
ClusterCapacityProviderAssociation. Therefore, in order to support both types on the same
cluster, Fargate capacity providers must also be specified as a
ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster
resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.
SoManyHs added a commit to SoManyHs/aws-cdk that referenced this issue Jun 8, 2021
Previously, adding/enabling Fargate capacity providers would add the
FARGATE and FARGATE_SPOT capacity providers a part of the
[capacityProviders
field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders)
on the ECS::Cluster resource. However, ASG Capacity Providers can only
be specified as part of the [capacityProviders field on the
ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of
type must all be specified *either* on the cluster *or* as a
ClusterCapacityProviderAssociation. Therefore, in order to support both types on the same
cluster, Fargate capacity providers must also be specified as a
ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster
resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.
SoManyHs added a commit to SoManyHs/aws-cdk that referenced this issue Jun 9, 2021
Previously, adding/enabling Fargate capacity providers would add the
FARGATE and FARGATE_SPOT capacity providers a part of the
[capacityProviders
field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders)
on the ECS::Cluster resource. However, ASG Capacity Providers can only
be specified as part of the [capacityProviders field on the
ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of
type must all be specified *either* on the cluster *or* as a
ClusterCapacityProviderAssociation. Therefore, in order to support both types on the same
cluster, Fargate capacity providers must also be specified as a
ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster
resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.
SoManyHs added a commit to SoManyHs/aws-cdk that referenced this issue Jun 9, 2021
Previously, adding/enabling Fargate capacity providers would add the
FARGATE and FARGATE_SPOT capacity providers a part of the
[capacityProviders
field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders)
on the ECS::Cluster resource. However, ASG Capacity Providers can only
be specified as part of the [capacityProviders field on the
ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of
type must all be specified *either* on the cluster *or* as a
ClusterCapacityProviderAssociation. Therefore, in order to support both types on the same
cluster, Fargate capacity providers must also be specified as a
ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster
resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.
@mergify mergify bot closed this as completed in #15012 Jun 9, 2021
mergify bot pushed a commit that referenced this issue Jun 9, 2021
… Cluster (#15012)

Previously, adding/enabling Fargate capacity providers would add the FARGATE and FARGATE_SPOT capacity providers a part of the [capacityProviders field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders) on the ECS::Cluster resource. However, ASG Capacity Providers can only be specified as part of the [capacityProviders field on the ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of type must all be specified *either* on the cluster *or* as a ClusterCapacityProviderAssociation.  Therefore, in order to support both types on the same cluster, Fargate capacity providers must also be specified as a ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster resource and adds them as a ClusterCapacityProviderAssociation.

Fixes #14730.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Jun 9, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
… Cluster (aws#15012)

Previously, adding/enabling Fargate capacity providers would add the FARGATE and FARGATE_SPOT capacity providers a part of the [capacityProviders field](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html#cfn-ecs-cluster-capacityproviders) on the ECS::Cluster resource. However, ASG Capacity Providers can only be specified as part of the [capacityProviders field on the ECS::ClusterCapacityProviderAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html#cfn-ecs-clustercapacityproviderassociations-capacityproviders)
resource, due to circular dependency issues.

However, when a cluster is created, any capacity providers regardless of type must all be specified *either* on the cluster *or* as a ClusterCapacityProviderAssociation.  Therefore, in order to support both types on the same cluster, Fargate capacity providers must also be specified as a ClusterCapacityProviderAssociation.

This change removes the Fargate capacity providers from the Cluster resource and adds them as a ClusterCapacityProviderAssociation.

Fixes aws#14730.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants