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

New_to_work picture New_to_work · Oct 5, 2018 · Viewed 8.8k times · Source

I want to list all the AWS AMI's (Amazon Machine Image) that I can see using the console and Boto 3.

I have tried using describe_instances() to get ImageIDs but not all the images are getting listed.

Answer

John Rotenstein picture John Rotenstein · Oct 5, 2018
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. If you leave out the 'self' bit, it will list all publicly-accessible AMIs (and the list is BIG!).