在执行 AWS 文档中的 put-object-tagging 示例时遇到错误。

huangapple go评论82阅读模式
英文:

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 &#39;{&quot;TagSet&quot;: [{ &quot;Key&quot;: &quot;designation&quot;, &quot;Value&quot;: &quot;confidential&quot; }]}&#39;

but it throws this error:

usage: aws [options] &lt;command&gt; &lt;subcommand&gt; [&lt;subcommand&gt; ...] [parameters]
To see help text, you can run:

  aws help
  aws &lt;command&gt; help
  aws &lt;command&gt; &lt;subcommand&gt; help

Unknown options: Key:, designation,, Value:, confidential, }]}&#39;, [{

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 &#39;TagSet=[{Key=designation,Value=confidential}]&#39;

which resulted in a different error:

Error parsing parameter &#39;--tagging&#39;: Expected: &#39;=&#39;, received: &#39;&#39;&#39; for input:
&#39;TagSet={Key=designation,Value=confidential}&#39;
^

答案1

得分: 0

我尝试了以下命令,使用Windows Powershell,没有任何问题。

aws s3api put-object-tagging --bucket my-bucket --key OSI-Model.png --tagging &#39;TagSet=[{Key=DataSecurity,Value=Confidential},{Key=Department,Value=HR},{Key=TagBy,Value=Bob}]&#39;

所以,一个解决方案是使用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 &quot;TagSet=[{Key=DataSecurity,Value=Confidential}, {Key=Department,Value=HR}, {Key=TagBy,Value=Bob}]&quot;
英文:

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 &#39;TagSet=[{Key=DataSecurity,Value=Confidential},{Key=Department,Value=HR},{Key=TagBy,Value=Bob}]&#39;

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 &quot;TagSet=[{Key=DataSecurity,Value=Confidential}, {Key=Department,Value=HR}, {Key=TagBy,Value=Bob}]&quot;

huangapple
  • 本文由 发表于 2023年6月5日 00:30:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401386.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定