Aws ec2 create-tags with quotes

amazon-web-servicesaws-cli

I can't seem to create a tag on a resource if the value contains a quote. For example:

aws ec2 create-tags --resource $someResource --tags 'Key=mykey,Value={"json":"value"}'

fails with:

Error parsing parameter '--tags': should be: Key value pairs, with multiple values separated by a space.

But if I run it without the quotes in the value, it succeeds:

aws ec2 create-tags --resource $someResource --tags 'Key=mykey,Value={json:value}'

I've tried a few different combinations of quoting/escaping, but I just can't seem to set the JSON value from the CLI.

For completeness, I updated my tools yesterday:

aws --version
aws-cli/1.3.6 Python/2.7.5 Darwin/13.1.0

Thanks!

Best Answer

Bumped into the same problem, and found a way to circumvent this unexpected behaviour I think: aws ec2 create-tags --resource $someResource --tags Key=mykey,Value='"{\"json\":\"value\"}"'

A bit overdue maybe, but someone might find it useful. The matter is that the awscli seems to try to parse what's inside the quotes to a variable, and if it is not default to a string, it will give an error. So within the quotes, another set of quotes needs to be used, so that it will default to a string.