Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create EC2 instance without given Image-Id in AWS template?

I want to create a RHEL OS EC2 Instance using AWS template. I don't have any RHEL instance currently. So don't have any Image-ID.

like image 542
Paritosh Upadhyay Avatar asked Oct 17 '22 21:10

Paritosh Upadhyay


1 Answers

Red Hat maintains RHEL AMIs. We can use the CLI describe-images to query their public AMIs based on:

  • Account ID: 309956199498
  • A known string pattern matching their AMI names: RHEL-*_HVM_GA-*-Hourly2-GP

For the sake of this example, we will sort the images by CreationDate, request only the last element in the collection (via -1) and filter the results down to Name, ImageId, and CreationDate.

Example:

aws ec2 describe-images \
    --owners 309956199498 \
    --filters "Name=name,Values=RHEL-*_HVM_GA-*-Hourly2-GP2" \
    --query 'sort_by(Images, &CreationDate)[-1].[Name, ImageId, CreationDate]' \
    --output text

Output:

RHEL-7.3_HVM_GA-20161026-x86_64-1-Hourly2-GP2   ami-b63769a1    2016-10-26T22:32:29.000Z

To verify this is correct, you can double-check by visiting the 'Quick Start' section of the AWS Console's EC2 'Launch Instances' Wizard and checking the most recent RHEL AMI that is sorted near the top of this quick start listing. At the time of this posting, the most recent RHEL AMI was ami-b63769a1.

The AWS EC2 Console, showing the most recent RHEL AMI.

After this, you would take that resulting ImageId and use it as part of your request to launch a new instance.

Further Reading:

  • AWS Documentation - Finding a Linux AMI
like image 134
Anthony Neace Avatar answered Oct 21 '22 08:10

Anthony Neace