Search code examples
pythonamazon-web-servicesamazon-ec2boto3amazon-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.

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


Solution

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