Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 374
New_to_work Avatar asked Dec 07 '22 13:12

New_to_work


1 Answers

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!).

like image 164
John Rotenstein Avatar answered Dec 23 '22 02:12

John Rotenstein