Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (12.9k points)

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?

1 Answer

0 votes
by (18.2k points)

You can use describe-images command on AWS CLI.

As shown below:

aws ec2 describe-images \

    --owners 'aws-marketplace' \

    --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' \

    --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \

    --output 'text'

Here, the values of owner and product code are taken from the AMI product codes published in the wiki by CentOS.

https://wiki.centos.org/Cloud/AWS

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Jan 14, 2020 in AWS by R. Raman (790 points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...