如何在DescribeImagesRequest中按名称过滤描述的图像?

时间:2013-05-27 14:45:33

标签: java amazon-web-services amazon-ec2

我正在尝试检查特定的AMI是否存在。所以,我在做:

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

(代码是Scala而不是Java,但这并不是真正相关的)。我遇到以下异常:

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]

如何正确定义DescribeImagesRequest的过滤器?

1 个答案:

答案 0 :(得分:3)

TL; DR - 使用name代替Name作为密钥。

为了调查,我转向我当地安装的ec2工具,然后运行

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

有一个类似的错误,更加Google友好:

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

Googlging让我接受了这个blog post,之后这个工作从命令行开始:

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

现在,在这次无关的游览之后,我发现了一个简单的问题:我尝试Name作为键,而事实上键应该是小写的name