英文:
Getting error on executing put-object-tagging example from aws documentation
问题
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 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}'
^
答案1
得分: 0
我尝试了以下命令,使用Windows Powershell,没有任何问题。
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}]'
所以,一个解决方案是使用Powershell而不是cmd。
我将尝试找到Windows cmd的解决方案,并且如果成功执行,将更新此答案。
更新
我找到了使用Windows cmd执行的解决方案。解决方案是从我的命令中移除单引号,例如以下命令在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}]
然而,如果在TagSet
内部存在空格,那么没有引号的解决方案将失败,例如以下命令失败:
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}]
最佳解决方案由用户Compo提供,解决方案是使用双引号,例如以下命令在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}]"
英文:
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.
Update
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}]"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论