(aws_ecs): Add support for `DefaultCapacityProviderStrategy` to the `Cluster` L2 construct
See original GitHub issueStep Function state language does not support provider parameter for running ECS task https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html. I think default provider is the only option there. To use it conveniently from CDK, there is an open ticket with a described workaround https://github.com/aws/aws-cdk/issues/7967#issuecomment-651583630.
Proposed Solution
The L2 construct a2s_ecs.Cluster
currently doesn’t support a default provider, could you please add it?
https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ecs/Cluster.html#aws_cdk.aws_ecs.Cluster.add_asg_capacity_provider
I tried to use L1 constructs and ran into several issues. CfnCluster.default_capacity_provider_strategy
(via CapacityProviderStrategyItemProperty
) and CfnClusterCapacityProviderAssociations
expect provider as a string instead of specific type. This is probably not a problem of CDK as the AWS::ECS::ClusterCapacityProviderAssociations
in CloudFormation docs have a similar problem. Examples in the docs are fine. Could you please forward the problem to the correct place?
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecs.CfnCluster.CapacityProviderStrategyItemProperty.html
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecs.CfnClusterCapacityProviderAssociations.html
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-clustercapacityproviderassociations.html
I tried to create the association using a generic CfnResource
, i came up with this:
ecs_cluster = ecs.Cluster(...)
provider = ecs.AsgCapacityProvider(...)
association = CfnResource(self, "capacity_association2",
type="AWS::ECS::ClusterCapacityProviderAssociations",
properties= {
"CapacityProviders": [
provider.node.children[0].ref
],
"Cluster": ecs_cluster.node.default_child.ref,
"DefaultCapacityProviderStrategy": [
{
"CapacityProvider": provider.node.children[0].ref
}
]
}
)
In Python CDK, ecs.AsgCapacityProvider
did not have a default_child
, so to access its reference, I had to use provider.node.children[0].ref
Environment
- CDK CLI Version : 1.108.1
- **Framework Version: ** 1.108.1
- Node.js Version: v10.19.0
- OS : Ubuntu
- Language (Version): 3.8.5
Other
To run an ECS task from step function using a custom provider from CDK, there is currently an open ticket with a described workaround https://github.com/aws/aws-cdk/issues/7967#issuecomment-651583630.
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:11 (3 by maintainers)
Was able to get around this issue using Aspects
And then in the construct that’s creating the cluster
I’ve got a branch that I’ll create a PR for once I’ve added tests as suggested by docs https://github.com/aws/aws-cdk/compare/main...piotrromanowski:aws-cdk:Add_cluster_service_capacity_provider_support
Edit: FWIW we’ve been using this in production for a while now and it’s been working out well