A little-known recent feature is the ability to Query for the latest Amazon Linux AMI IDs using AWS Systems Manager Parameter Store | AWS Compute Blog.

The namespace is made up of two parts:

  • Parameter Store Prefix (tree): /aws/service/ami-amazon-linux-latest/
  • AMI name alias: (example) amzn-ami-hvm-x86_64-gp2

These:

aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn*" --query 'sort_by(Images, &CreationDate)[].Name'

Get-EC2ImageByName -Name amzn* | Sort-Object CreationDate | Select-Object Name

can be changed into:

aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 --region us-east-1 

Get-SSMParameter -Name /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 -region us-east-1

Plus, it can be used in a CloudFormation template:

# Use public Systems Manager Parameter
 Parameters :
 LatestAmiId :
 Type : 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
 Default: ‘/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2’

Resources :
 Instance :
 Type : 'AWS::EC2::Instance'
 Properties :
 ImageId : !Ref LatestAmiId
Answer from John Rotenstein on Stack Overflow
🌐
Amazon Web Services
aws.amazon.com › amazon linux ami
AWS | Amazon Linux AMI
2 weeks ago - The Amazon Linux AMI is a supported and maintained Linux image provided by Amazon Web Services for use on Amazon Elastic Compute Cloud (Amazon EC2). It is designed to provide a stable, secure, and high performance execution environment for applications running on Amazon EC2.
Discussions

Best way to find AMI ID of Amazon Linux 2 for each region for a CloudFormation map?
https://aws.amazon.com/blogs/compute/query-for-the-latest-amazon-linux-ami-ids-using-aws-systems-manager-parameter-store/ More on reddit.com
🌐 r/aws
5
1
September 18, 2018
amazon web services - Get latest AMI ID for AWS instance - Stack Overflow
A little-known recent feature is the ability to Query for the latest Amazon Linux AMI IDs using AWS Systems Manager Parameter Store | AWS Compute Blog. More on stackoverflow.com
🌐 stackoverflow.com
amazon ec2 - Is there a list of AMIs for every popular linux distribution and version - Stack Overflow
I need to test a piece of software against every linux distribution/version. I'm going to use amazon AWS Is there a list of AMIs somewhere that I can just copy paste into my script to automate this More on stackoverflow.com
🌐 stackoverflow.com
How to find the right ami id for amazon linux 2 - Stack Overflow
I have only found it so far by chat gpt, but not by googling or by using the proposed way from aws: aws ec2 describe-images --owners amazon nor is the AMI shown in the EC2 console the correct one.... More on stackoverflow.com
🌐 stackoverflow.com
🌐
AWS
aws.amazon.com › blogs › compute › query-for-the-latest-amazon-linux-ami-ids-using-aws-systems-manager-parameter-store
Query for the latest Amazon Linux AMI IDs using AWS Systems Manager Parameter Store | Amazon Web Services
September 14, 2018 - This post is courtesy of Arend Castelein, Software Development Engineer – AWS Want a simpler way to query for the latest Amazon Linux AMI? AWS Systems Manager Parameter Store already allows for querying the latest Windows AMI. Now, support has been expanded to include the latest Amazon Linux AMI.
Top answer
1 of 7
26

A little-known recent feature is the ability to Query for the latest Amazon Linux AMI IDs using AWS Systems Manager Parameter Store | AWS Compute Blog.

The namespace is made up of two parts:

  • Parameter Store Prefix (tree): /aws/service/ami-amazon-linux-latest/
  • AMI name alias: (example) amzn-ami-hvm-x86_64-gp2

These:

aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn*" --query 'sort_by(Images, &CreationDate)[].Name'

Get-EC2ImageByName -Name amzn* | Sort-Object CreationDate | Select-Object Name

can be changed into:

aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 --region us-east-1 

Get-SSMParameter -Name /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 -region us-east-1

Plus, it can be used in a CloudFormation template:

# Use public Systems Manager Parameter
 Parameters :
 LatestAmiId :
 Type : 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
 Default: ‘/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2’

Resources :
 Instance :
 Type : 'AWS::EC2::Instance'
 Properties :
 ImageId : !Ref LatestAmiId
2 of 7
12

AWS CLI

A way to filter the output and get the only the required attributes is using a combination of filters,queries on the aws describe-images command as below:

aws ec2 describe-images \
--owners 'amazon' \
--filters 'Name=description,Values=Amazon Linux AMI*' \
--query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \
--output 'text'

Command Explanation:

  • owners : For images by amazon, use 'amazon'. To query your own images, use 'self'
  • filters : You can use a list of filters to filter out the instance that you are looking for. I prefer description because I found the name filter missing for some images. Values support wildcards. More on filters
  • query : Query can be used to filter only what is required from the output. You can also sort on fields that would be present in the output. I have sorted on the images and the creation date to get the last created image and filtered the ImageId
  • output : Output can be json or text based on the way you plan to consume it.

Using Python

You can do the same using the below python script:

import boto3
from operator import itemgetter

client = boto3.client('ec2')
response = client.describe_images(
    Filters=[
        {
            'Name': 'description',
            'Values': [
                'Amazon Linux AMI*',
            ]
        },
    ],
    Owners=[
        'amazon'
    ]
)
# Sort on Creation date Desc
image_details = sorted(response['Images'],key=itemgetter('CreationDate'),reverse=True)
ami_id = image_details[0]['ImageId']

Update:

You can use fine-grain filters to get a quicker response. The filters mentioned in @Jack's answer work.

filters = [ {
    'Name': 'name',
    'Values': ['amzn-ami-hvm-*']
},{
    'Name': 'description',
    'Values': ['Amazon Linux AMI*']
},{
    'Name': 'architecture',
    'Values': ['x86_64']
},{
    'Name': 'owner-alias',
    'Values': ['amazon']
},{
    'Name': 'owner-id',
    'Values': ['137112412989']
},{
    'Name': 'state',
    'Values': ['available']
},{
    'Name': 'root-device-type',
    'Values': ['ebs']
},{
    'Name': 'virtualization-type',
    'Values': ['hvm']
},{
    'Name': 'hypervisor',
    'Values': ['xen']
},{
    'Name': 'image-type',
    'Values': ['machine']
} ]

# Use above filters 
response = client.describe_images(
  Filters=filters,
  Owners=[
      'amazon'
  ]
)
🌐
AWS
docs.aws.amazon.com › amazon linux › user guide › using al2023 on aws › al2023 on amazon ec2
AL2023 on Amazon EC2 - Amazon Linux 2023
4 weeks ago - You can determine which AL2023 AMI ID is needed by looking at the AMI list in the Amazon EC2 console. Or, you can use AWS Systems Manager. If you're using Systems Manager, make sure to select the AMI alias from those that are listed in the previous section. For more information, see Query for the latest Amazon Linux ...
🌐
Medium
moosakhalid.medium.com › fetching-amazon-linux-ami-id-using-ssm-and-terraform-or-aws-cloudformation-9963c9555a24
Fetching Amazon Linux AMI-ID using SSM and Terraform or AWS CloudFormation | by Moosa Khalid | Medium
January 24, 2021 - Yes, you heard it right, there are publicly available(region-based) SSM parameters which you can poll and get the AMI-ID against, so you don’t have to use expensive aws ec2 decribe-images API calls with complex filters to look for and sort the latest Amazon AMI’s. How would one accomplish this you may ask……well, keep on reading. You’ll need to query the public SSM parameter path exposed by AWS, exactly for this purpose. The base path for every SSM parameter that pertains to Amazon Linux image would be:
Find elsewhere
🌐
Ubuntu Cloud Images
cloud-images.ubuntu.com › locator › ec2
Ubuntu Amazon EC2 AMI Finder
1- Locate the AMI-ID by searching the table below 2- Assuming your ec2 environment is setup, run an instance by “ec2-run-instances ami-xxxxx -O AWS_ACCESS_KEY -W AWS_SECRET_KEY” OR click the ami ID, which will direct you to the AWS console Note:Versions ending in EOL are end-of-life and are provided for reference only
🌐
Amazon Web Services
aws.amazon.com › amazon linux ami › faqs
Amazon Linux AMI FAQs
2 weeks ago - When the yum process on your instance downloads packages from those buckets, information about that S3 connection is logged. Within the context of the Amazon Linux AMI, the report_instanceid=yes setting allows the Amazon Linux AMI repositories to also log the instance id (i-xxxxxxxx) and region ...
🌐
Fundamentals-of-devops
fundamentals-of-devops.com › resources › 2025 › 02 › 24 › finding-ami-ids
How to find AMI IDs for Amazon Linux and Ubuntu
February 24, 2025 - <NAME> is the name of the AMI, which will be al2023-ami-2023.*-x86_64 for Amazon Linux and ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-* for Ubuntu 24.04. For example, to look up the ID of the most recent Amazon Linux 2023 AMI in us-east-2, authenticate to AWS, and then run the following command:
🌐
AWS
docs.aws.amazon.com › amazon ecs › developer guide › amazon ecs clusters › amazon ecs capacity providers for ec2 workloads › amazon ec2 container instances for amazon ecs › amazon ecs-optimized linux amis › retrieving amazon ecs-optimized linux ami metadata
Retrieving Amazon ECS-optimized Linux AMI metadata - Amazon Elastic Container Service
For an example of how to use the Systems Manager parameter, see Create an Amazon ECS cluster with the Amazon ECS-optimized Amazon Linux 2023 AMI in the AWS CloudFormation User Guide. The AMI ID, image name, operating system, container agent version, source image name, and runtime version for ...
🌐
Educative
educative.io › answers › how-to-find-a-linux-ami-using-the-amazon-ec2-console
How to find a Linux AMI using the Amazon EC2 console
Under the “Application and OS ... case, it would be “Amazon Linux.” ... Step 7: Once the operating system is selected, the AMI ID appears below in the same section....
🌐
Stack Overflow
stackoverflow.com › questions › 79216425 › how-to-find-the-right-ami-id-for-amazon-linux-2
How to find the right ami id for amazon linux 2 - Stack Overflow
I have only found it so far by chat gpt, but not by googling or by using the proposed way from aws: aws ec2 describe-images --owners amazon nor is the AMI shown in the EC2 console the correct one....
🌐
Amazon Web Services
docs.aws.amazon.com › amazon ec2 › user guide › amazon machine images in amazon ec2
Amazon Machine Images in Amazon EC2 - Amazon Elastic Compute Cloud
Understand what is included in an AMI, how to work with them, and how they are used when you launch an Amazon EC2 instance.
🌐
AWS
docs.aws.amazon.com › amazon emr documentation › management guide › plan, configure and launch amazon emr clusters › working with amazon linux amis in amazon emr › using a custom ami to provide more flexibility for amazon emr cluster configuration
Using a custom AMI to provide more flexibility for Amazon EMR cluster configuration - Amazon EMR
Therefore, to provision an m5.xlarge using a custom AMI, your custom AMI should also have x86_64 architecture. Similarly, to provision an m6g.xlarge instance, which has arm64 architecture, your custom AMI should have arm64 architecture. For more information about identifying a Linux AMI for ...
🌐
Micro Focus
microfocus.com › documentation › arcsight › arcsight-platform-21.1 › as_platform_admin_guide › Content › deployment_cloud › AMI_ID_determine.htm
Determining the AMI ID - Micro Focus
AMI IDs are unique to each AWS Region. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. (Note: This link opens an external web site.) You can also get new image IDs by running OS-based commands: For CentOS Linux 7, run the following command: # aws ec2 describe-images \ --filters ...