5

Is there any way to query for free tier AMI ID's using EC2 CLI tools?

karthik101
  • 1,619
  • 4
  • 17
  • 23
  • would anyone care to say why they have down voted my question? – karthik101 Jan 28 '15 at 09:20
  • free-tier is not an "image" thing. Free-tier is related to the machine specs. t1.micro is often the "free-tier" machine for many images. An example aws cli command that will fire up a free tier machine: aws ec2 run-instances --image-id ami-8635a9b6 --instance-type t1.micro --placement AvailabilityZone=us-west-2a --security-groups YOUR_SECURITY_GROUP_NAME --key-name YOUR_KEY_NAME – Mamun Mar 04 '16 at 17:49

4 Answers4

3

There is not a way to directly query "free tier" using the CLI, but you can figure out which ones are free tier if you look at the criteria listed on the Amazon free tier page.

An example of a command for finding only public images hosted by Amazon: aws ec2 describe-images --owners self amazon

Looking at both the Amazon free tier page & the possible options for describe-images, it is possible to find an image within the free tier. I like to be exact, so I use the above command & --filter by machine type, until I find the one that matches the Amazon EC2 Linux t2.micro instance.

brienna
  • 1,415
  • 1
  • 18
  • 45
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Rosário Pereira Fernandes Feb 28 '18 at 21:17
  • Added an explanation, @RosárioPereiraFernandes – brienna Mar 04 '18 at 15:58
1

The free tier is much more about the instance type than the AMI.

However, you can query images using describe-images like this:

aws ec2 describe-images

That returns (in my case) a 45mb response. To narrow the selection, parse the resultinng JSON and remove any entries that have a ProductCodes key, which are marketplace entries.

tedder42
  • 23,519
  • 13
  • 86
  • 102
1

Get the current Free tier Amazon Linux 2 AMI

aws ec2 describe-images \
--owners amazon \
--filters "Name=name,Values=amzn2-ami-hvm-2.0.????????.?-x86_64-gp2" "Name=state,Values=available" \
--query "reverse(sort_by(Images, &Name))[:1].ImageId" \
--region sa-east-1 \
--output text

Source: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html

Rodrigo Ibañez
  • 129
  • 2
  • 5
0

i am a newbie to AWS. i too had difficulties with the aws ec2 describe-images --filter option.

i went to the page AMIs page and after some experiments came up with the following command line for aws ec2 describe-images for the requirement i had at hand.

$ aws ec2 describe-images --owner amazon --filter "Name=description,Values=*Ubuntu*" "Name=owner-alias,Values=amazon" "Name=architecture,Values=x86_64" "Name=image-type,Values=machine" "Name=root-device-name,Values=/dev/sda1" "Name=root-device-type,Values=ebs" "Name=virtualization-type,Values=hvm"

i piped the output to jq '.Images|length' and saw that the number of results decreased with the addition of each new filter argument.

Please note that Name=xxxxx given in the describe-images differ from the 'Resource Attribute' names that would be given in the filter edit box in the url sited above.

ksridhar
  • 189
  • 2
  • 9