代码之家  ›  专栏  ›  技术社区  ›  boardrider Patrick K

如何找到谁创建了AWS AMI?

  •  0
  • boardrider Patrick K  · 技术社区  · 6 年前

    我创作了一个boto3脚本

      1 import boto3
      2 
      3 #STATUSES = ( 'available', 'pending' )
      4 REGIONS = ('us-west-1', 'us-east-1', 'us-west-2')
      5 REGIONS_H = ('N. California', 'N. Virginia', 'Oregon')
      6 
      7 for i in range(len(REGIONS)):
      8     region = REGIONS[i]
      9     region_h = REGIONS_H[i]
     10     print()
     11     print("Images in {}".format(region_h))
     12     print("-----------------------")
     13     rds = boto3.setup_default_session(region_name=region)
     14     rds = boto3.client('rds')
     15 
     16     ec2 = boto3.resource('ec2')
     17     images = ec2.images.filter(Owners=['self'])
     18     for image in images:
     19         print("[{}] ( {} {} {} {} )".format(image.state, image.id, image.image_type, image.architecture, image.description, image.platform))
    

    这给了我以下输出(bravity分级):

    Images in N. California
    -----------------------
    [available] ( ami-02efeb026dba996f8 machine x86_64 Base system for testing Progressive install )
    [available] ( ami-046bd9fc47f29a58f machine x86_64 bb-rhel7-install-5 )
    [available] ( ami-04c2959b96500208c machine x86_64 bb-ubuntu-install-3 )
    

    有没有办法添加到第19行,这样我可以显示

    0 回复  |  直到 6 年前
        1
  •  2
  •   bot    6 年前

    image.owner_id 将返回图像所有者的AWS帐户ID。参考 this 链接。

        2
  •  0
  •   mkrana    6 年前

    访问AMI元数据有多种方法,在本例中,AMI元数据是使用ec2资源访问的,因此您需要引用 EC2 resources

    image.owner-id

    推荐文章