如何使用python boto3列出特定区域中的所有Amazon Machine Image(AMI)?

时间:2018-07-30 08:31:55

标签: python amazon-web-services boto3

我需要使用boto3列出特定区域(例如us-east-1)中的所有ami。到目前为止,不需要过滤器。我只需要列出所有amis。任何帮助表示赞赏。提前致谢。

1 个答案:

答案 0 :(得分:1)

此操作的重要部分是指定self作为所有者,否则您将收到每个公共AMI的列表!

import boto3

# Get a list of all AMIs owned by this account_id
client = boto3.client('ec2', region_name='us-east-1')

response = client.describe_images(Owners=['self'])

for ami in response['Images']:
  print (ami['ImageId'])  # Or whatever you wish to do

请参阅:describe_images() documentation