How to filter described images by name in DescribeImagesRequest?

I am trying to check if a specific AMI exists. So I do:

val filter = new Filter().withName("Name").withValues(amiName) val result = ec2.describeImages(new DescribeImagesRequest().withFilters(filter)) result.getImages.size() > 0 

(Scala code, not Java, but this is not relevant). I get the following exception:

 com.amazonaws.AmazonServiceException: The filter 'Name' is invalid at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:644) ~[aws-java-sdk-1.4.2.1.jar:na] at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:338) ~[aws-java-sdk-1.4.2.1.jar:na] at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:190) ~[aws-java-sdk-1.4.2.1.jar:na] at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:6199) ~[aws-java-sdk-1.4.2.1.jar:na] at com.amazonaws.services.ec2.AmazonEC2Client.describeImages(AmazonEC2Client.java:2905) ~[aws-java-sdk-1.4.2.1.jar:na] 

How to properly define a filter for DescribeImagesRequest?

+4
source share
1 answer

TL DR - use name instead of name as a key.

To explore, I turned to the local installation of ec2 tools and ran

 ec2-describe-images -o self -F name=myaminame 

Received a similar error, which was more Google friendly:

 Filter definitions must have format 'name=value', but found 'name' 

Googlging drew me to a blog post and then it worked from the command line:

 ec2-describe-images -o self -F "name=myaminame" 

Now, after this unrelated tour, I just found a simple problem: I tried name as a key, but in fact the key should be a lowercase name .

+3
source

Source: https://habr.com/ru/post/1482987/


All Articles