I am trying to execute the following example from https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object-tagging.html on Windows-11 cmd
aws s3api put-object-tagging --bucket my-bucket --key doc1.rtf --tagging '{"TagSet": [{ "Key": "designation", "Value": "confidential" }]}'
but it throws this error:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: Key:, designation,, Value:, confidential, }]}', [{
I have changed the bucket name and object name in the command. The CLI user also has the right permission.
I also tried the following way:
aws s3api put-object-tagging --bucket my-bucket --key doc1.rtf --tagging 'TagSet=[{Key=designation,Value=confidential}]'
which resulted in a different error:
Error parsing parameter '--tagging': Expected: '=', received: ''' for input:
'TagSet={Key=designation,Value=confidential}'
^
I tried the following command with Windows Powershell and it worked without any problem.
aws s3api put-object-tagging --bucket my-bucket --key OSI-Model.png --tagging 'TagSet=[{Key=DataSecurity,Value=Confidential},{Key=Department,Value=HR},{Key=TagBy,Value=Bob}]'
So, one solution is to use Powershell instead of cmd.
I will try to find a solution for Windows cmd and update this answer if I successfully execute it with cmd.
I found the solution to execute it with Windows cmd. The solution was to remove single quotes from my command e.g. the following command runs successfully with Windows cmd.
aws s3api put-object-tagging --bucket my-bucket --key OSI-Model.png --tagging TagSet=[{Key=DataSecurity,Value=Confidential},{Key=Department,Value=HR},{Key=TagBy,Value=Bob}]
However, without quotes, this solution fails if there is whitespace inside TagSet
e.g. the following command fails:
aws s3api put-object-tagging --bucket my-bucket --key OSI-Model.png --tagging TagSet=[{Key=DataSecurity,Value=Confidential}, {Key=Department,Value=HR}, {Key=TagBy,Value=Bob}]
The best solution was provided by the user, Compo and the solution was to use double quotes e.g. the following command runs successfully with Windows cmd:
aws s3api put-object-tagging --bucket my-bucket --key OSI-Model.png --tagging "TagSet=[{Key=DataSecurity,Value=Confidential}, {Key=Department,Value=HR}, {Key=TagBy,Value=Bob}]"