【问题标题】:aws cli returning unknown options on create-image commandaws cli 在 create-image 命令上返回未知选项
【发布时间】:2021-05-13 17:35:57
【问题描述】:

我正在运行下面的命令以从现有的带有标签的 ec2 服务器创建 ami。下面是我在 redhat linux 8.3 上运行的命令

aws ec2 create-image --instance-id $instance_id --name "$ami_name" --region $region --description "$desc" --no-reboot --tags-specifications 'ResourceType=image,Tags=[{Key='Owner',Value='Some_one'},{Key='Environment',Value='Production:Dev'},{Key='Stack',Value='ETL'},{Key='Role',Value='Database'}]'

我正确替换了所有变量,但是 --tags-specifications 存在一些问题。 我尝试了以下带有标签规范的选项,但它们都不适合我。

--tags-specifications 'ResourceType=image,Tags=[{Key=Owner,Value="Some_one"},{Key=Environment,Value="Production:Dev"},{Key=Stack,Value="ETL"},{Key=Role,Value="Database"}]'
--tags-specifications 'ResourceType=image,Tags=[{Key=Owner,Value=Some_one},{Key=Environment,Value=Production:Dev},{Key=Stack,Value=ETL},{Key=Role,Value=Database}]'
--tags-specifications 'ResourceType=image,Tags=[{Key='Owner',Value="Some_one"},{Key='Environment',Value="Production:Dev"},{Key='Stack',Value="ETL"},{Key='Role',Value="Database"}]'
--tags-specifications, ResourceType=image,Tags=[{Key="Owner",Value="Some_one"},{Key="Environment",Value="Non-Production:Dev"},{Key="Stack",Value="ETL"},{Key="Role",Value="Database"}]

谁能告诉我这里出了什么问题?

【问题讨论】:

  • 您的 aws-cli 版本是什么?
  • 我有以下 aws-cli 版本。 # aws --version aws-cli/2.0.30 Python/3.7.3 Linux/4.18.0-240.22.1.el8_3.x86_64 botocore/2.0.0dev34
  • 下面是运行命令python3 -m pip install awscli --upgrade后的版本。 # aws --version aws-cli/1.19.70 Python/3.6.8 Linux/4.18.0-240.22.1.el8_3.x86_64 botocore/1.20.70

标签: linux bash amazon-web-services aws-cli


【解决方案1】:

您没有指定错误是什么或您正在使用的 aws cli 版本。当您更正了 --tag-specification 的错字时,我猜问题可能是您使用的 aws-cli 版本。

December 2020 之前,AWS 没有在创建映像期间添加标签的选项。如果您碰巧有一个几个月前的 aws-cli 版本,当您运行命令创建映像并添加标签时,您可能会收到类似于以下内容的错误:

unknown options: --tag-specifications, ResourceType=image,Tags=[{Key=somekey,Value=some value}]

如果是这种情况,请尝试升级您的 aws cli。不确定您是如何安装它的,但如果您使用 pip,假设您确实可以访问更高版本,则应该使用以下内容对其进行升级:

python3 -m pip install awscli --upgrade

【讨论】:

  • 似乎是 aws-cli 版本问题。在 --upgrade 命令之后更新 aws-cli 版本后,一切正常,除了我的实例配置文件角色没有足够的权限。我正在处理权限。谢谢。
  • @ShaileshSutar 很高兴它起作用了。请记住在上面标记为已回答。
【解决方案2】:

应该是--tag-specifications:

aws ec2 create-image --instance-id $instance_id --name "$ami_name" --region $region --description "$desc" --no-reboot --tag-specifications 'ResourceType=image,Tags=[{Key='Owner',Value='Some_one'},{Key='Environment',Value='Production:Dev'},{Key='Stack',Value='ETL'},{Key='Role',Value='Database'}]'

【讨论】:

  • 我用以下组合尝试了您的建议,但没有奏效。 'ResourceType=image,Tags=[{Key=Owner,Value=Some_one},{Key=Environment,Value=Non-Production:Dev},{Key=Stack,Value=ETL},{Key=Role,Value=Database}]' 'ResourceType=image,Tags=[{Key='Owner',Value="Some_one"},{Key='Environment',Value="Non-Production:Dev"},{Key='Stack',Value="ETL"},{Key='Role',Value="Database"}]' 'ResourceType=image,Tags=[{Key="Owner",Value="Some_one"},{Key="Environment",Value="Non-Production:Dev"},{Key="Stack",Value="ETL"},{Key="Role",Value="Database"}]'
  • @ShaileshSutar 为什么它不起作用?有什么错误吗?
  • 没有错误。仅在 --Tag-specification 的情况下返回未知选项,但是在 pip upgrade 命令之后,错误消失了。
猜你喜欢
  • 2020-06-12
  • 1970-01-01
  • 2020-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-15
  • 1970-01-01
  • 2020-02-21
相关资源
最近更新 更多