4

I'm trying to check whether a specific AMI exists. So, I'm doing:

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

(code is Scala and not Java, but that's not really relevant). I'm getting 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 do I correctly define a filter to the DescribeImagesRequest?

4

1 回答 1

3

TL;DR - use name instead of Name as the key.

To investigate, I turned to my local installation of ec2 tools, and ran

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

Got a similar error that was more Google friendly:

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

Googlging got me to this blog post, and afterwards this worked from the command line:

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

Now, after this unrelated excursion, I just found the simple problem: I tried Name as key, while in fact the key should be lowercase name.

于 2013-05-27T14:57:54.437 回答