简体   繁体   English

如何使用 boto3 获取所有 AWS AMI 的列表?

[英]How to get the list of all AWS AMIs using boto3?

I want to list all the AWS AMI's (Amazon Machine Image) that I can see using the console and Boto 3.我想列出使用控制台和 Boto 3 可以看到的所有 AWS AMI(亚马逊机器映像)。

I have tried using describe_instances() to get ImageIDs but not all the images are getting listed.我曾尝试使用describe_instances()来获取 ImageID,但并非所有图像都被列出。

import boto3

ec2_client = boto3.client('ec2', region_name='ap-southeast-2') # Change as appropriate

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

This lists all AMIs that were created by your account.这会列出您的账户创建的所有 AMI。 If you leave out the 'self' bit, it will list all publicly-accessible AMIs (and the list is BIG!).如果您省略“self”位,它将列出所有可公开访问的 AMI(并且列表很大!)。

import boto3
ec2 = boto3.client('ec2', region_name=region)
response = ec2.describe_instances()
for reservation in response["Reservations"]:
    for instance in reservation["Instances"]:
        print(instance["ImageId"])

This will give you list of all the used AMI ids in aws account you own这将为您提供您拥有的 aws 帐户中所有已使用的 AMI ID 的列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM