good morning. Does anyone have any advice for tagging a user with the AWS CLI? I am following the AWS documentation found here for adding tags to a user: https://docs.aws.amazon.com/cli/latest/reference/iam/tag-user.html The example they provide is:
aws iam tag-user --user-name alice --tags '{"Key": "Department", "Value": "Accounting"}'
This is the command I am running for my purposes:
aws iam tag-user --user-name access-Arnav-peg-eng --tags '{"Key": "access-project", "Value": "peg"}'
When I run the command, however, I receive the following error:
Error parsing parameter '--tags': Expected: '=', received: ''' for input:
'{Key:
^
I have tried a number of different permutations and combinations figuring maybe the CLI has changed but the documentation hasn't been updated, but none of those worked.
Some examples included:
aws iam tag-user --user-name access-Arnav-peg-eng --tags "{"Key"="access-control","Value"="peg"}"
aws iam tag-user --user-name access-Arnav-peg-eng --tags '[{"Key"="access-control","Value"="peg"}]'
And so on. Have I been typing something wrong? Has the CLI changed and the documentation doesn't reflect that? Each time I try to add a tag to a user from the command line, it doesn't work. I know everything is properly configured. I have been creating users and performing other actions from it. I am using aws-cli/2.2.44 Python/3.8.8 Windows/10 exe/AMD64 prompt/off.
Does anyone have any suggestions? Thanks in advance.
CodePudding user response:
The provided example does not work on Windows. See Using quotation marks with strings in the AWS CLI, specifically the Windows command prompt
tab.
Try:
aws iam tag-user ^
--user-name alice ^
--tags "{\"Key\": \"Department\", \"Value\": \"Accounting\"}"
Note that I made my example multi-line for clarity (via the caret at the end of each partial line), but you can remove the carets and joins the lines together, if you prefer, like so:
aws iam tag-user --user-name alice --tags "{\"Key\": \"Department\", \"Value\": \"Accounting\"}"
The key thing is that the Windows command prompt requires double quotation marks "..."
to enclose the JSON data structure, so you have to escape any embedded double quotes like so: \"