Search code examples
amazon-ec2aws-cli

AWS - Unable to apply tags with values containing spaces


I am trying to apply the tags manually for the ebs volumes created using the below aws cli command. Reason for manually applying the tags is due to installation error with Pivotal cloud foundry.

My tag key/value pairs contains spaces. Is there a way to add spaces and still make the cli command work. this is my cli command:

Does not work: aws ec2 create-tags --resources ami-4778889 vol-1445333--tags Key=Name,Value=PCF Key=Product Family,Value=Enterprise Services

Works with underscore aws ec2 create-tags --resources ami-4778889 vol-1445333--tags Key=Name,Value=PCF Key=Product_Family,Value=Enterprise_Services

Any idea on how to fix this? Appreciate your help!

AWS CLI: aws-cli/1.16.24 Python/3.6.0 Windows/10 botocore/1.12.14


Solution

  • This works by quoting each pair of "Key,Value" like this:

    aws ec2 create-tags --resources vol-448655jbvhyhgh --tags "Key=A Test,Value=PCF A Test" "Key=B Test,Value=PCFB Test"
    

    If you use double quotes you can expand shell variables in either the Key value or in the Value value.