Reputation: 61
We're using the AWS CDK to deploy a large part of our infrastructure, including ECS resources. I have a file that creates an ECS cluster, task definition and tasks. Per the Tag class I'm then using Tag.add() to apply a tag to everything in the scope of the file, including all ECS resources.
When I deploy the stack, the tag applies to the cluster and the task definition, but not the task. I also don't get any error messages; the tag just silently doesn't apply to the task. Applying tags directly to the task doesn't seem to be a supported workaround so I'm stuck. Does anyone know the solution to get the task tagged?
Upvotes: 3
Views: 1741
Reputation: 2762
If you are using the ECS patterns constructs (eg, ApplicationLoadBalancedFargateService) you can get this working by adding the following flags:
enable_ecs_managed_tags=True,
propagate_tags=aws_ecs.PropagatedTagSource.TASK_DEFINITION,
After that point my tags propogated from my CDK stack to the ECS cluster/service/task definitions and then into the underlying tasks.
Upvotes: 2
Reputation: 489
Applying tags directly to the task doesn't seem to be a supported workaround so I'm stuck.
I'm not too familiar with ECS tasks, but have you tried to write the tags to the CloudFormation Resource construct directly?
From https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html:
Modifying the AWS CloudFormation Resource behind AWS Constructs
If an [sic] Construct is missing a feature or you are trying to work around an issue, you can modify the CFN Resource that is encapsulated by the Construct.
All Constructs contain within them the corresponding CFN Resource...
The basic approach to get access to the CFN Resource class is to use
construct.node.defaultChild
(Python:default_child
), cast it to the right type (if necessary), and modify its properties.Raw Overrides
If there are properties that are missing from the CFN Resource, you can bypass all typing using raw overrides. This also makes it possible to delete synthesized properties.
Use one of the
addOverride
methods (Python:add_override
) methods, as shown in the following example.# Get the AWS CloudFormation resource cfn_bucket = bucket.node.default_child # Use dot notation to address inside the resource template fragment cfn_bucket.add_override("Properties.VersioningConfiguration.Status", "NewStatus") cfn_bucket.add_deletion_override("Properties.VersioningConfiguration.Status") # add_property_override is a convenience function, which implies the # path starts with "Properties." cfn_bucket.add_property_override("VersioningConfiguration.Status", "NewStatus") cfn_bucket.add_property_deletion_override("VersioningConfiguration.Status")
Upvotes: 0