【问题标题】:How to filter not equal to in AWS CLI如何在 AWS CLI 中过滤不等于
【发布时间】:2019-12-16 14:21:52
【问题描述】:

我正在尝试查找所有非窗口图像:

aws ec2 describe-images --region us-east-2 --image-ids ami-** --filters "Name=platform, Values=windows"

以上为我提供了所有 Windows 平台 ID。有没有办法不在这个cli里面?我试过价值!=,。通过stackoverflow搜索但没有找到任何东西。

【问题讨论】:

  • 您只想找到自己的自己的图像,还是所有可公开访问的图像?如果只是你自己的,你会想要包含owner=self,否则你会得到数百张图片。
  • aws cli 没有反向过滤,因此您需要使用其他功能。见This

标签: amazon-web-services amazon-ec2 aws-cli amazon-ami


【解决方案1】:

此 Python3 代码将列出您自己帐户的所有 Windows AMI:

import boto3

ec2_client = boto3.client('ec2', region_name='us-east-2')

images = ec2_client.describe_images(Owners=['self'])

for image in images['Images']:
    if 'Platform' not in image:
        print(image['ImageId'])

【讨论】:

    【解决方案2】:

    您可以像这样在 cli 命令上使用查询

    aws ec2 describe-images --image-ids ami-** --region us-east-2 --query 'Images[?Platform != `windows`]'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 2016-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      相关资源
      最近更新 更多