By using AWS re:Post, you agree to the Terms of Use

Using tags with spaces with cloudformation deploy


Due to an unfortunate choice of tags for billing we are stuck with trying to tag all resources with a tag with a space in it. "OTAP Environment".
From documentation:
--tags (list) A list of tags to associate with the stack that is created or updated. AWS CloudFormation also propagates these tags to resources in the stack if the resource supports it. Syntax: TagKey1=TagValue1 TagKey2=TagValue2 ...

From my development laptop (Windows) it seems to work:
sam deploy --template-file serverless-output.yml --capabilities CAPABILITY_IAM --parameter-overrides Environment=t --tags "OTAP Environment=T" --stack-name myStack
(sam deploy = aws cloudformation deploy)

However, when running this in a linux docker (Alpine) via Gitlab it does not work. Of course I tried other quotes. ' and `. With the latter I expected it to work, were it not the tags seems to disappear because of the GitLab Runner.

This may be more a gitlab issue than an AWS CLI issue, but if tagging were possible without the space seperation (in json maybe?) I could automate it.

5 Answers

spaces aren't supported
This is the regex for key names:

answered 4 years ago

It has worked on a windows machine, with the proper quotes, hence I know it is possible via AWS CLI. Still not sure about the GitLab + AWS CLI combination.

And it is possible from the console.

I found this in documentation:
The key name of the tag. You can specify a value that is 1 to 127 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.

answered 4 years ago

My bad..I was referencing the incorrect regex.

The SAM cli is just a wrapper on top of the cloudformation cli..have you tried using the cf cli directly?

aws cloudformation deploy

answered 4 years ago

Yes, I have tried that as well. From a Windows laptop it is possible with the right quotes.

--tags "OTAP Environment=T"

Would work in that case. But haven't got it to run on a Gitlab runner. But the solution is no longer needed as the required tag has changed to a tag without a space :-D

answered 4 years ago

Answer is no longer needed as the required tag name changed.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions