【问题标题】:AWS describe-images with filter to exclude by tag value带有过滤器的 AWS 描述图像以按标签值排除
【发布时间】:2022-11-08 08:24:11
【问题描述】:

我想在我的帐户中查找图像并通过具有某些值的标签排除。例如,以下是不允许的:

aws ec2 describe-images --owners self --filters "Name=tag:commit_hash_short,Values!=[5d6447e,c001fab]"

但反过来确实有效:

aws ec2 describe-images --owners self --filters "Name=tag:commit_hash_short,Values=[5d6447e,c001fab]"

有没有办法进行这种操作?

【问题讨论】:

  • 不,您不能进行否定查询。您必须获取所有图像,然后自己过滤它们。

标签: amazon-web-services amazon-ami


【解决方案1】:

根据 Marcin 的建议,这可以使用 jq 排除 1 个值(MYCOMMITHASH),但我不确定如何将其更改为列表。

aws ec2 describe-images --owners self --query "Images[*].{ImageId:ImageId,commit_hash_short:[Tags[?Key=='commit_hash_short']][0][0].Value}" | jq 'del(.[] | select(.commit_hash_short == "MYCOMMITHASH"))'

【讨论】:

    【解决方案2】:

    我建议使用--queries 来获得您正在寻找的输出。一个例子可能是这样的:

    aws ec2 describe-images --owners self --query 'Images[?!not_null(Tags[?Key == `commit_hash_short` && Value == `5d6447e`])]' |jq -r '.[].ImageId'
    

    我是根据我自己的类似努力和类似this one 的文章做出此回应的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 2017-12-09
      • 2017-05-25
      相关资源
      最近更新 更多