AWS CloudFormation
Cloud Templates
Stack Tags
AWS Infrastructure
Cloud Management

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.

Practice system design

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:

yaml
1Resources:
2  AppBucket:
3    Type: AWS::S3::Bucket
4    Properties:
5      Tags:
6        - Key: Environment
7          Value: Production
8        - Key: Owner
9          Value: PlatformTeam

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:

bash
aws cloudformation create-stack   --stack-name demo-stack   --template-body file://template.yaml   --tags Key=Environment,Value=Production Key=Owner,Value=PlatformTeam

And when updating:

bash
aws cloudformation update-stack   --stack-name demo-stack   --template-body file://template.yaml   --tags Key=Environment,Value=Production Key=Owner,Value=PlatformTeam

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:

yaml
1Parameters:
2  EnvironmentName:
3    Type: String
4
5Resources:
6  AppBucket:
7    Type: AWS::S3::Bucket
8    Properties:
9      Tags:
10        - Key: Environment
11          Value: !Ref EnvironmentName
12
13  AppTopic:
14    Type: AWS::SNS::Topic
15    Properties:
16      Tags:
17        - Key: Environment
18          Value: !Ref EnvironmentName

Then pass the parameter during deployment:

bash
aws cloudformation create-stack   --stack-name demo-stack   --template-body file://template.yaml   --parameters ParameterKey=EnvironmentName,ParameterValue=Production   --tags Key=Environment,Value=Production

This pattern keeps stack metadata and resource metadata aligned without pretending they are controlled in the same place.

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.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design