Why don't my stack-level tags propagate to resources in my CloudFormation stack?

3 minute read
2

My stack-level tags don't propagate to resources in my AWS CloudFormation stack.

Resolution

Propagation of stack-level tags to resources can vary by resource. CloudFormation propagates stack-level tags only for resources with the Tags property. For a list of AWS resources and their property types, see AWS resource and property types reference.

The resource supports the Tags property

If your resource supports the Tags property, then your CloudFormation stack has the stack-level tags with the aws: prefix.

For example, the Amazon Simple Storage Service (Amazon S3) AWS::S3::Bucket resource supports the Tags property. Create a stack with the AWS::S3::Bucket resource and then specify stack-level tags. After you create the stack, the S3 bucket resource has the propagated stack-level tags.

The resource doesn't support the Tags property

If your resource doesn't support the Tags property, then your CloudFormation stack doesn't have the stack-level tags.

For example, the PutRule API allows you to specify tags, but the Amazon EventBridge AWS::Events::Rule resource doesn't support the Tags property. Create a stack with the AWS::Events::Rule resource and then specify stack-level tags. After you create the stack, the Events Rule resource doesn't have the propagated stack-level tags.

But if the resource API supports adding tags after resource creation, you can use a CloudFormation custom resource to apply the tags. To implement this solution, first create an AWS Lambda function. Then, use the AWS SDKs to write custom code that applies tags to your resource. Use the cfn-response module to allow the Lambda function to serve as a Lambda backed custom resource. Finally, in the CloudFormation template, use a DependsOn attribute to make sure that the initial resource is created before the stack creates the custom resource.

For example, after CloudFormation creates the AWS::Events::Rule resource, the custom resource defined in the template creates and then invokes the Lambda backed custom resource. The Lambda function uses the TagResource API to apply custom tags to the existing resource. Then, the Lambda function signals success to the CloudFormation stack.

Search for or create an issue through GitHub

If a stack-level tag doesn't propagate for a resource that supports the Tags property, then check whether this is a known issue. For a list of known issues, see cloudformation-coverage-roadmap on the GitHub website. If the issue isn't submitted as an issue, then to create an issue, choose New issue.

AWS OFFICIAL
AWS OFFICIALUpdated 5 months ago