Reputation: 1791
How can I get AWS Ec2 image id using describe instance
Java SDK api for a given operating system which is free tier as well for the given region?
I tried to use the describe Instance api
but I don't know how to use Filters
.
AmazonEC2ClientBuilder.defaultClient().describeImages(new DescribeImagesRequest().withFilters(Arrays.asList(
new Filter().withName("is-public").withValues("true"),
new Filter().withName("some name i dont know").withValues("some values i dont know")
)))
I am struggling with getting an image Id, it returns a lot of images using only is-public
filter. I want to get free tier eligible instances of core os only, no extra software installed like SQL server, etc.
I tried this documentation but couldn't understand much.
To be very precise, I want to get the AMI ids of images which are given at AWS console while launching an Instance marked as free tier eligible as shown in image below
Please give me a example code snippet for getting a ubuntu 18.04 LTS
ami-id of this free tier eligible Image shown in image above i.e. ami-02d55cb47e83a99a0
. And suggest how can i change it to get AMI id for some another images like Suse or debian or redhat etc.
P.S:
I suppose these AMI ids are different for each region even for same operating system, I think the solution should include something like region
for getting image id in that region. In the solution, please include the solution for ap-south-1
as this screenshot is for this region.
Edit 1
I know it has something to do with Filtering name
or description
. I can use wildcards in the withValue()
, like i want to search for AMI like new Filter().withName("description").withValue("*ubuntu-18.04*")
where *
is wildcard character. But it returns all the AMIs which contains ubuntu-18.04
in description, including all those paid AMIS which have existing software installed. How can I filter to get only free tier eligible, basic, default ubuntu image.
Upvotes: 1
Views: 4308
Reputation: 1353
Being free-tier eligible has more to do with the instance type, not so much with the AMI itself. By that logic, if you could find all AMIs that will work with a free-tier eligible instance type like t2.micro
, it should serve your purpose. Fortunately, AWS Marketplace search has an Instance Type
filter. The following Marketplace URL finds free AMIs by AWS in ap-south-1
compatible with t2.micro
:
Do the same using AWS Java SDK to get the AMIs programmatically.
Upvotes: 1