Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have been launching EC2 instances by logging in to the AWS site, hitting the "Launch" button and following the proscribed steps. Now I'd like to launch instance from an Ansible script, and to do this I (think I) need the AMI ID of the image I wish to launch.

The problem is that I am launching an image from the "Marketplace", and I cannot find the AMI ID. In particular I'm using the Centos 7 image. This is easy to find in the web interface, just go to the marketplace and search for "centos", the image I want is the first one found, but the information provided about the image doesn't seem to include the AMI ID that I need to launch it from a script. The workaround is to manually launch an image, and then when inspecting the running image, the AMI ID is given. But is there an easier way to find it?

like image 542
bandjalong Avatar asked Nov 28 '16 01:11

bandjalong


People also ask

How do I find my AWS Marketplace AMI ID?

To find the most recent AMI for your account, you can search with an AMS SKMS CLI command or use the AMS console details page for relevant VPC: Use the AMS console: Available AMIs are listed on the AMI page in the AMS console. Select from AMIs with names that begin with "customer-".

Is Amazon AMI on CentOS?

AMI is definitely CentOS 6. x, whereas Amazon Linux 2 is CentOS 7.

What is my AMI in AWS?

An Amazon Machine Image (AMI) is a supported and maintained image provided by AWS that provides the information required to launch an instance. You must specify an AMI when you launch an instance. You can launch multiple instances from a single AMI when you require multiple instances with the same configuration.

Does AWS have CentOS 7?

Product Overview. This is the Official CentOS 7 x86_64 HVM image that has been built with a minimal profile, suitable for use in HVM instance types only. The image contains just enough packages to run within AWS, bring up an SSH Server and allow users to login.


1 Answers

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.

like image 174
Anthony Neace Avatar answered Sep 18 '22 08:09

Anthony Neace