-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Describe the bug
I'm unable to create a managed instance capacity provider. It appears the current L2 constructs creates an invalidate (and not required) ClusterCapacityProviderAssociations
resource.
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
The managed instances capacity provider gets added to the cluster.
Current Behavior
The creation of the stack fails because the Capacity Provider Associate resource fails
Reproduction Steps
Template:
// Create ECS Cluster
const cluster = new ecs.Cluster(this, 'MyEcsCluster', {
vpc: vpc,
clusterName: `${this.stackName}-cluster`,
});
// Create a Default Managed Instances Capacity Provider
const miDefaultCapacityProvider = new ecs.ManagedInstancesCapacityProvider(this, 'MIDefaultCapacityProvider', {
infrastructureRole: ecsInfrastructureRole,
ec2InstanceProfile: ecsInstanceProfile,
subnets: vpc.privateSubnets,
securityGroups: [miDefaultSecurityGroup]
});
cluster.addManagedInstancesCapacityProvider(miDefaultCapacityProvider);
When I synth this, I get the following template:
MyEcsCluster989E66E0:
Type: AWS::ECS::Cluster
Properties:
ClusterName: CdkStack-cluster
Metadata:
aws:cdk:path: CdkStack/MyEcsCluster/Resource
MyEcsCluster9940BE40:
Type: AWS::ECS::ClusterCapacityProviderAssociations
Properties:
CapacityProviders: []
Cluster:
Ref: MyEcsCluster989E66E0
DefaultCapacityProviderStrategy: []
Metadata:
aws:cdk:path: CdkStack/MyEcsCluster/MyEcsCluster
MIDefaultCapacityProvider07546591:
Type: AWS::ECS::CapacityProvider
Properties:
ClusterName:
Ref: MyEcsCluster989E66E0
ManagedInstancesProvider:
InfrastructureRoleArn:
Fn::GetAtt:
- ECSInfrastructureRoleE492121F
- Arn
InstanceLaunchTemplate:
Ec2InstanceProfileArn:
Fn::GetAtt:
- ECSInstanceProfileBA4A4DA9
- Arn
NetworkConfiguration:
SecurityGroups:
- Fn::GetAtt:
- MIDefaultSecurityGroup4EADDF9A
- GroupId
Subnets:
- Ref: MyVpcPrivateSubnetSubnet1SubnetE8BD536C
- Ref: MyVpcPrivateSubnetSubnet2SubnetE3BFCF91
Metadata:
aws:cdk:path: CdkStack/MIDefaultCapacityProvider/MIDefaultCapacityProvider
Then why I attempt to deploy it, the ClusterCapacityProviderAssociations
will fail.
Resource handler returned message: "Name is null" (RequestToken: f0729928-71d8-e634-55ef-aedadadfc136, HandlerErrorCode: InternalFailure)
Possible Solution
This additional Provider Association resource is not required with Managed Instances as the cluster name is in the capacity provider. I did wonder why we needed a cluster.addManagedInstancesCapacityProvider()
resource at all, we could have just added a cluster name attribute to ecs.ManagedInstancesCapacityProvider()
which would map to what the cloudformation looks like.
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.219.0
AWS CDK CLI version
2.1029.4
Node.js Version
v22.14
OS
Ubuntu 22.04
Language
TypeScript
Language Version
No response
Other information
No response