You can use command line parameters to list only the types of AMIs that interest you. For example, you can use the describe-images command as follows to find public AMIs owned by you or Amazon.
1 |
aws ec2 describe-images --owners self amazon |
Add the following filter to the previous command to display only AMIs backed by Amazon EBS:
1 |
--filters "Name=root-device-type,Values=ebs" |
After locating an AMI that meets your needs, write down its ID (ami-xxxxxxxx). You can use this AMI to launch instances. For more information, see Launching an Instance Using the AWS CLI in the AWS Command Line Interface User Guide.
Finding a CentOS 7 AMI ID 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:
1 2 3 4 5 6 |
aws ec2 describe-images \ --owners 'aws-marketplace' \ --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' \ --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \ --output 'text' \ --region eu-west-2 |
Output:
1 |
ami-e05a4d84 |
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.
Resources
-
Launch on EC2:CentOS 7 (x86_64) – with Updates HVM