簡體   English   中英

如何查找誰創建了AWS AMI?

[英]How to find who created an AWS AMI?

我創建了一個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?

image.owner_id將返回圖像所有者的AWS賬戶ID。 請參考鏈接。

有多種訪問AMI元數據的方法,在這種情況下,正在使用ec2資源訪問AMI元數據,因此您需要引用EC2資源

並且獲取所有者ID的調用應為image.owner-id

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM