Search code examples
javaamazon-web-servicesamazon-ec2amazon-amiaws-java-sdk

how to get list of all available images for a region in amazon web services using aws-java-sdk?


How can i get the list of all available images for a region using aws-java-sdk, I just tried with the below code, it is keep on executing for a long time.

AmazonEC2  ec2Client = new AmazonEC2Client(awsCredetials);
ec2Client.setRegion(RegionUtils.getRegion("us-west-2"));
DescribeImagesRequest request = new DescribeImagesRequest().withFilters(new LinkedList<Filter>());
DescribeImagesResult describeImagesResult= ec2Client.describeImages(request);

Solution

  • You are listing all public AMIs in us-west-2, there are over 50,000, add some filters.

    for example to find all 64bit Ubuntu AMIs:

    request.getFilters().add(new Filter().withName("architecture").withValues("x86_64"));
    request.getFilters().add(new Filter().withName("platform").withValues("Ubuntu"));
    

    See the complete list of filters here.