我一直在使用来自 Amazon 的新 rekognition API,但在从 IntelliJ 运行他们的示例Java 应用程序时遇到问题。我正在使用 Maven 构建项目,并将 AWS 开发工具包包含在我pom.xml
的如下:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
据我所知,我的应用程序似乎在这里的某个地方失败了:
AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(credentials)
.withEndpoint("s3-us-west-2.amazonaws.com");
rekognitionClient.setSignerRegionOverride("us-west-2");
try {
DetectFacesResult result = rekognitionClient.detectFaces(request);
ObjectMapper objectMapper = new ObjectMapper();
System.out.println("Result = " + objectMapper.writeValueAsString(result));
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
...我得到的错误是:
com.amazonaws.services.rekognition.model.AmazonRekognitionException: null (Service: AmazonRekognition; Status Code: 400; Error Code: null; Request ID: null)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1545)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1183)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:964)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:676)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:650)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:633)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$300(AmazonHttpClient.java:601)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:583)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:447)
at com.amazonaws.services.rekognition.AmazonRekognitionClient.doInvoke(AmazonRekognitionClient.java:1130)
at com.amazonaws.services.rekognition.AmazonRekognitionClient.invoke(AmazonRekognitionClient.java:1106)
at com.amazonaws.services.rekognition.AmazonRekognitionClient.detectFaces(AmazonRekognitionClient.java:599)
at com.github.jhenningsgaard.DetectFaces.main(DetectFaces.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
我还应该注意,我在 AWS CLI 中运行了操作(见下文)并且成功。
aws rekognition detect-faces \
--image '{"S3Object":{"Bucket":"Bucketname","Name":"s3ObjectKey"}}' \
--attributes "ALL" \
--region us-east-1 \
--profile adminuser