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

New*_*ork 4 python amazon-ec2 amazon-web-services boto3 amazon-ami

我想列出使用控制台和 Boto 3 可以看到的所有 AWS AMI(亚马逊机器映像)。

我曾尝试使用describe_instances()获取 ImageID,但并非所有图像都被列出。

Joh*_*ein 14

import boto3

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

images = ec2_client.describe_images(Owners=['self'])
Run Code Online (Sandbox Code Playgroud)

这会列出您的账户创建的所有 AMI。如果您省略“self”位,它将列出所有可公开访问的 AMI(并且列表很大!)。

  • 我想补充一点,describe_images() 返回一个字典。其详细记录如下:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_images (4认同)