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. It supports the latest EC2 instance ...
🌐
Amazon Web Services
docs.aws.amazon.com › amazon ec2 › user guide › amazon machine images in amazon ec2 › find an ami that meets the requirements for your ec2 instance
Find an AMI that meets the requirements for your EC2 instance - Amazon Elastic Compute Cloud
4 weeks ago - When selecting an AMI, consider the following requirements you might have for the instances that you want to launch: The AWS Region of the AMI as AMI IDs are unique to each Region. The operating system (for example, Linux or Windows).
Discussions

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
This might help: Query for the latest Amazon Linux AMI IDs using AWS Systems Manager Parameter Store | AWS Compute Blog ... I could find by simple going to ec2 and "create an instance". More on stackoverflow.com
🌐 stackoverflow.com
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
How to find an AMI ID.
Go to Kali's official website: https://www.kali.org/ Click Download: https://www.kali.org/get-kali/ Click Cloud. Click Amazon AWS. On the marketplace page, click Continue to Subscribe (the subscription is $0/hr on top of EC2 pricing, so it's fine): https://aws.amazon.com/marketplace/pp/prodview-fznsw3f7mq7to Once you've subscribed, you'll get an AMI ID you can use in Packer. More on reddit.com
🌐 r/aws
8
3
March 1, 2022
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
1 month ago - Launching AL2023 using the Amazon EC2 consoleLaunching AL2023 using the SSM parameter and AWS CLI Launching the latest AL2023 AMI using CloudFormationLaunching AL2023 using a specific AMI IDAL2023 AMI deprecation and life cycle · Use one of the following procedures to launch an Amazon EC2 instance ...
🌐
Ubuntu Cloud Images
cloud-images.ubuntu.com › locator › ec2
Ubuntu Amazon EC2 AMI Finder
You may search based on any of ... 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 ...
🌐
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 - Get-SSMParameter -Name /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 -region us-east-1 · After you have created the query, you can embed the command as a command substitution into your new instance launches. ... aws ec2 run-instances --image-id $(aws ssm get-parameters --names ...
🌐
AWS
docs.aws.amazon.com › amazon eks › user guide › manage compute resources by using nodes › create nodes with pre-built optimized images › create nodes with optimized amazon linux amis › retrieve recommended amazon linux ami ids
Retrieve recommended Amazon Linux AMI IDs - Amazon EKS
You can retrieve the image ID of ... Amazon Linux AMI with the following command, which uses the sub-parameter image_id. Make the following modifications to the command as needed and then run the modified command: Replace <kubernetes-version> with an Amazon EKS supported version. Replace ami-type with one of the following options. For information about the types of Amazon EC2 instances, see Amazon ...
Find elsewhere
🌐
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 - To use this functionality, you set the AMI ID to resolve:ssm:<AMI_NAME>, where <AMI_NAME> is /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 for Amazon Linux and /aws/service/canonical/ubuntu/server/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id for Ubuntu (see this link for others, such as Windows and macOS AMIs). For example, with the AWS CLI, you can launch an EC2 instance with the latest Amazon Linux AMI with 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
This parameter ensures that each ... applied to the EC2 instances. 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 ...
🌐
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
It should also match the EC2 instance architecture. For example, an m5.xlarge instance has an x86_64 architecture. 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 ...
🌐
LinuxVox
linuxvox.com › blog › amazon-linux-2-ami
Amazon Linux 2 AMI: A Comprehensive Guide — linuxvox.com
Then, use the following command to launch an instance: aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t2.micro \ --key-name my-key-pair \ --security-group-ids sg-0abcdef1234567890
🌐
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 images” section, select the “Quick start” tab and choose the desired operating system. In this case, it would be “Amazon Linux.” ... Step 7: Once the operating system is selected, the AMI ID appears ...
🌐
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
Amazon ECS-optimized Linux AMIs - Amazon Elastic Container Service
2 weeks ago - We recommend that you use the Amazon ECS-optimized Amazon Linux 2023 AMI for your Amazon EC2 instances. Launching your container instances from the most recent Amazon ECS-Optimized AMI ensures that you receive the current security updates and container agent version.
🌐
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 ...
🌐
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
This might help: Query for the latest Amazon Linux AMI IDs using AWS Systems Manager Parameter Store | AWS Compute Blog ... I could find by simple going to ec2 and "create an instance".
🌐
AWS re:Post
repost.aws › knowledge-center › launch-ecs-optimized-ami
Launch ECS instances with Amazon ECS optimized AMIs | AWS re:Post
May 23, 2024 - Use the AMI ID to launch your Amazon Linux container instance in us-east-1. You can also modify the command to return the machine image for a specific version and AWS Region. Use SSM parameters as input parameters for AWS CloudFormation templates.
🌐
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.