Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add spaces for aws cloudformation deploy --parameter-overrides and/or --tags?

I am trying to get spaces into the tags parameter for the aws cli and it works if I hardcode it but not if I use bash variables. What is going on and how do I fix it?

This works with out spaces:

aws cloudformation deploy  \
      --template-file /path_to_template/template.json \ 
      --stack-name my-new-stack \
      --tags Key1=Value1 Key2=Value2

This works with out spaces but with variables:

tags="Key1=Value1 Key2=Value2" 
aws cloudformation deploy \
  --template-file /path_to_template/template.json \ 
  --stack-name my-new-stack \
  --tags $tags

This works with spaces:

aws cloudformation deploy  \
  --template-file /path_to_template/template.json \ 
  --stack-name my-new-stack \
  --tags 'Key1=Value1' 'Key Two=Value2'

This does not work, spaces and variables:

tags="'Key1=Value1' 'Key Two=Value2'"

aws cloudformation deploy  \
  --template-file /path_to_template/template.json \ 
  --stack-name my-new-stack \
  --tags $tags

Attempting to fix bash expansion, also does not work, spaces and variables:

tags="'Key1=Value1' 'Key Two=Value2'"

aws cloudformation deploy  \
  --template-file /path_to_template/template.json \ 
  --stack-name my-new-stack \
  --tags "$tags"

Attempting to fix bash expansion, also does not work, spaces and variables:

tags="'Key1=Value1' 'Key Two=Value2'"

aws cloudformation deploy  \
  --template-file /path_to_template/template.json \ 
  --stack-name my-new-stack \
  --tags "$(printf '%q' $tags)"

Error:

Invalid parameter: Tags Reason: The given tag(s) contain invalid characters (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID

like image 955
vfrank66 Avatar asked Sep 05 '25 03:09

vfrank66


1 Answers

Would you please try:

tags=('Key1=Value1' 'Key Two=Value2')

aws cloudformation deploy  \
  --template-file /path_to_template/template.json \ 
  --stack-name my-new-stack \
  --tags "${tags[@]}"
like image 194
tshiono Avatar answered Sep 07 '25 19:09

tshiono