How to find AMI ID of CentOS 7 image in AWS Marketplace?

CentOS publishes their AMI product codes to their wiki. The wiki provides the following information for the latest CentOS 7 AMI:

  • Owner: aws-marketplace
  • Product Code: aw0evgkw8e5c1q413zgy5pjce

Using this information, we can query describe-images with the AWS CLI:

Example:

aws ec2 describe-images \
    --owners 'aws-marketplace' \
    --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' \
    --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \
    --output 'text'

Output:

ami-6d1c2007

This query returns a single AMI ID, selected by sorting the collection by creation date and then selecting the last (most recent) element in the collection.

Per the CentOS wiki, multiple AMI ids may be associated with a product key, so while this query would currently only return a single AMI because only one matching this product currently exists... in the future if a new AMI is created for this product code for any reason this query will return it instead.


If you are looking for all Centos7 images

$ aws ec2 describe-images \
      --owners aws-marketplace \
      --filters Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce \
      --query 'Images[*].[CreationDate,Name,ImageId]' \
      --filters "Name=name,Values=CentOS Linux 7*" \
      --region us-west-2 \
      --output table \
  | sort -r
|  2018-06-13T15:58:14.000Z|  CentOS Linux 7 x86_64 HVM EBS ENA 1805_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-77ec9308.4  |  ami-3ecc8f46  |
|  2018-05-17T09:30:44.000Z|  CentOS Linux 7 x86_64 HVM EBS ENA 1804_2-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-55a2322a.4   |  ami-5490ed2c  |
|  2018-04-04T00:11:39.000Z|  CentOS Linux 7 x86_64 HVM EBS ENA 1803_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-8274d6ff.4  |  ami-0ebdd976  |
|  2017-12-05T14:49:18.000Z|  CentOS Linux 7 x86_64 HVM EBS 1708_11.01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-95096eef.4   |  ami-b63ae0ce  |

add to it similar query available for RedHat

aws ec2 describe-images \
    --owners 309956199498 \
    --query 'Images[*].[CreationDate,Name,ImageId]' \
    --filters "Name=name,Values=RHEL-7.?*GA*" \
    --region us-east-1 \
    --output table \
  | sort -r
|  2018-03-23T20:42:08.000Z |  RHEL-7.5_HVM_GA-20180322-x86_64-1-Hourly2-GP2  |  ami-6871a115 |
|  2017-08-08T15:37:31.000Z |  RHEL-7.4_HVM_GA-20170808-x86_64-2-Hourly2-GP2  |  ami-c998b6b2 |
|  2017-07-24T15:44:39.000Z |  RHEL-7.4_HVM_GA-20170724-x86_64-1-Hourly2-GP2  |  ami-cdc999b6 |
|  2016-10-26T22:32:29.000Z |  RHEL-7.3_HVM_GA-20161026-x86_64-1-Hourly2-GP2  |  ami-b63769a1 |
|  2015-11-12T21:06:58.000Z |  RHEL-7.2_HVM_GA-20151112-x86_64-1-Hourly2-GP2  |  ami-2051294a |
|  2015-02-25T20:24:23.000Z |  RHEL-7.1_HVM_GA-20150225-x86_64-1-Hourly2-GP2  |  ami-12663b7a |
|  2015-02-09T22:54:40.000Z |  RHEL-7.0_HVM_GA-20150209-x86_64-1-Hourly2-GP2  |  ami-60a1e808 |
|  2014-10-17T20:29:24.000Z |  RHEL-7.0_HVM_GA-20141017-x86_64-1-Hourly2-GP2  |  ami-a8d369c0 |
|  2014-05-28T19:17:11.000Z |  RHEL-7.0_GA_HVM-x86_64-3-Hourly2               
|  ami-785bae10 |

Check in this page

or

AWS has been changing the “aws marketplace” UI. Now (2020) We get the ami id in the “configure this software” Page in the AWS Marketplace itself.

Steps:

  1. Search and locate the image. Click on the image.
  2. On the top right, click “continue to subscribe”
  3. On the next window, click on “Continue to configuration”
  4. On the next window, Find the Ami ID located. We can change software versions to get different ami Ids.