'How to add stack-level tags to cloudformation stack deployed using SAM

I'm trying to add tags to a stack while using SAM deploy, but they're not showing up. The SAM cli command code can be found below.

sam deploy --stack-name test-stack --resolve-image-repos --capabilities CAPABILITY_NAMED_IAM --no-fail-on-empty-changeset --template-file ./.aws-sam/build/template.yaml --resolve-s3 --tags Name=test-stack az:zone=infra

Tags are not being created in the CloudFormation stack despite giving the —tag parameter to the cli.

Can someone tell me how to add stack-level tags to the CloudFormation stack that is deployed using SAM CLI?



Solution 1:[1]

I'll rather suggest to put them in the samconfig.toml file, like:

[default.deploy.parameters]
stack_name = "your-application"
s3_bucket = "your-s3-for-cloudformation-stuff"
s3_prefix = "your-folder-name"
...
tags = "Name=\"test-stack\" az:zone=\"infra\""

That will propagate tags down to all the resources of the stack (including CloudFormation stack itself)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leopoldo Varela