【问题标题】:How to find who created an AWS AMI?如何找到谁创建了 AWS AMI?
【发布时间】:2019-04-25 23:48:36
【问题描述】:

我创建了一个 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))

这给了我以下输出(为勇敢而删减):

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 行,以便我可以显示 创建了 AMI?

【问题讨论】:

    标签: amazon-web-services amazon-ec2 boto3 amazon-ami


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      有多种方法可以访问 AMI 元数据,在这种情况下,使用 ec2 资源访问 AMI 元数据,因此您需要参考EC2 resources

      获取所有者 ID 的调用应该是 image.owner-id

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多