AWS cloud formation Template- providing Tags for the stack in the template
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
CloudFormation lets you tag resources inside the template, but root stack tags are not typically declared in the template body itself. Instead, you pass stack tags when you create or update the stack through the CLI, SDK, API, or console.
Stack Tags Versus Resource Tags
This is the key distinction:
- stack tags belong to the CloudFormation stack object
- resource tags belong to individual AWS resources created by the stack
If you are looking for a top-level Tags section in the template for the stack itself, that is usually the wrong model. The template defines resources and their properties. The stack metadata, including stack tags, is supplied when the stack operation runs.
For example, these are resource tags inside the template:
Those tags apply to the S3 bucket, not to the CloudFormation stack object itself.
How to Pass Stack Tags
When creating the stack from the AWS CLI, pass them with --tags:
And when updating:
In the console, there is a dedicated stack tags section during stack creation and update. The same idea applies through SDK calls and infrastructure tooling that wraps CloudFormation.
What About Tag Propagation
Some stack tags propagate automatically to supported resources. That is useful, but it is not universal. You should not assume that every resource will inherit stack tags in the way you expect.
Because propagation rules vary by service, the safest approach is:
- pass stack tags for stack-level management and reporting
- set resource tags explicitly inside the template where the service supports them
That way your cost allocation and governance tags are visible even if automatic propagation is incomplete.
Parameterizing Resource Tags in the Template
If you want the same environment value reused across many resources, parameterize it:
Then pass the parameter during deployment:
This pattern keeps stack metadata and resource metadata aligned without pretending they are controlled in the same place.
Nested Stacks and Related Cases
The one place where template-driven tagging can be confusing is nested stacks. A nested stack is itself a resource of type AWS::CloudFormation::Stack, so it can expose properties that do not exist at the root template level.
That does not change the main answer for the top-level stack. For the root stack, stack tags are an operation-time concern, not a normal template-root property.
Common Pitfalls
The most common mistake is trying to add a top-level Tags section to the template and expecting CloudFormation to treat it as root stack metadata. That is not how standard stack creation works.
Another issue is assuming stack tags automatically become resource tags everywhere. Some resources inherit them, some do not, and the details are service-specific.
Developers also sometimes tag only the stack or only the resources, then wonder why cost reporting or governance filters are incomplete. Use both levels deliberately when tag visibility matters.
Finally, do not hard-code environment values all over the template. Use parameters for repeated resource tag values so deployments stay consistent across environments.
Summary
- Root stack tags are usually passed at stack create or update time, not declared as a template-root section.
- Resource tags are defined inside resource
Properties. - Use CLI, SDK, API, or console inputs to set stack tags.
- Do not rely blindly on automatic stack-tag propagation to resources.
- Parameterize repeated tag values to keep stack and resource tagging consistent.
Related reading
- AWS Cloudformation- How to do string Uppercase or lowercase in json/yaml template
- AWS Cloudformation Conditionally create properties of resources
- AWS CloudFormation create-stack vs deploy
- AWS Cloudformation How to reuse bash script placed in user-data parameter when creating EC2?
- AWS Cloudwatch Filter and Pattern Syntax
- AWS CloudWatch Logs Insights - export full query result?
- AWS CloudFormation Stack update error Requires capabilities CAPABILITY_IAM
- AxisError axis 1 is out of bounds for array of dimension 1 when calculating accuracy of classes

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.