🌐
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

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
amazon web services - Get latest AMI ID for AWS instance - Stack Overflow
I wanted to fetch the latest ami id for AWS Linux machine while creating an ec2 instance for an autoscaling architecture. I was trying the aws cli to get the images types, but it would print out a... 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
Few questions regarding ubuntu ami id in AWS missing in Amazon EC2 AMI Locator for ubuntu - Stack Overflow
I am fetching the latest available ami id for ubuntu 18.04 LTS available in AWS with the below script export AWS_DEFAULT_REGION=us-east-1 aws ec2 describe-images \ --filters Name=name,Values=ubuntu/ More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - Start using AL2023 by setting up a new instance in the AWS CLI using the CloudFormation AMI ID parameter.
🌐
Tenable
tenable.com › plugins › nessus › 168612
Amazon Linux AMI : kernel (ALAS-2022-1645) | Tenable®
User interaction is not needed for exploitation.Product: AndroidVersions: Android kernelAndroid ID: A-223375145References: Upstream kernel (CVE-2022-20369) - Non-transparent sharing of return predictor targets between contexts in some Intel(R) Processors may allow an authorized user to potentially enable information disclosure via local access. (CVE-2022-26373) - A flaw use after free in the Linux kernel NILFS file system was found in the way user triggers function security_inode_alloc to fail with following call to function nilfs_mdt_destroy.
🌐
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....
🌐
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 - AWSTemplateFormatVersion: '2010-09-09' Parameters: ImageId: Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id> Description: Use an Image from SSM Parameter Store Default: /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id Resources: EC2Instance: Type: AWS::EC2::Instance Properties: InstanceType: t3.micro SecurityGroups: [!Ref 'EC2SecurityGroup'] ImageId: !Ref ImageId EC2SecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: SSH access SecurityGroupIngress: - IpProtocol: tcp FromPort: '22' ToPort: '22' CidrIp: 0.0.0.0/0 ... OpenSSL v3 vulnerability: Are all ECS-optimized AMIs affected or just the Amazon Linux 2022 based ones?
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'
  ]
)
Find elsewhere
🌐
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 ...
🌐
End of Life Date
endoflife.date › amazon-linux
Amazon Linux | endoflife.date
2 weeks ago - It was announced as Amazon Linux 2022 and renamed to Amazon Linux 2023.
🌐
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.
🌐
Ubuntu Cloud Images
cloud-images.ubuntu.com › locator › ec2
Ubuntu Amazon EC2 AMI Finder
For example if you would like to find out the AMI-ID for the latest release of “Precise” Pangolin to run on a “64″ bit “ebs” instance in the “us-east” region, you would search for “pre 64 us-east ebs” or a subset thereof. As soon as you start typing into the search box, the list zooms-in on the entries that match your criteria. You may search based on any of the column headers below Here’s how to start an instance using the AMI ID you just found
🌐
AWS Marketplace
aws.amazon.com › marketplace › pp › prodview-4us4yprgzaxks
AWS Marketplace: Amazon Linux 2 AMI (amazon linux 2) | Support by SupportedImages
This product has charges associated with it for seller support. The Amazon Linux 2 AMI is a stable, secure, and high-performance Linux environment optimized for the AWS Cloud. With long-term support and regular maintenance, this Amazon Linux 2 AMI provides the latest features for enterprise-level ...
🌐
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:
🌐
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
# aws ec2 describe-images \ --filters "Name=description,Values=Amazon Linux AMI *" "Name=architecture,Values=x86_64" "Name=virtualization-type,Values=hvm" \ "Name=root-device-type,Values=ebs" "Name=owner-alias,Values=aws-marketplace" | jq '.Images | sort_by(.CreationDate) | [last]' Record the ImageId value in the AWS worksheet. Next Step: Selecting a Bastion Hardware Instance Type · © 2022 Micro Focus or one of its affiliates ·
🌐
Red Hat
access.redhat.com › solutions › 15356
Red Hat Enterprise Linux Images (AMI) Available on Amazon Web Services (AWS) - Red Hat Customer Portal
March 6, 2025 - Note: Do not modify the command option --owners 309956199498. This is the account ID used to show Red Hat images. If you need to list images for AWS GovCloud, use --region us-gov-west-1 and --owners 219670896067. See What Is AWS GovCloud (US)?