我有一个超级简单的mvn项目,该项目正在运行一些代码,以根据arn获取Lambda函数的标签。
public static void listTag(String lambdaArn) {
final AWSLambdaAsync lambdaClient = AWSLambdaAsyncClientBuilder.standard()
.withRegion(Regions.EU_WEST_1)
.build();
final ListTagsRequest listTagsRequest = new ListTagsRequest();
listTagsRequest.setResource(lambdaArn);
final ListTagsResult listTagsResult = lambdaClient.listTags(listTagsRequest);
final Map<String, String> tags = listTagsResult.getTags();
...
}
代码运行正常,我可以获取标签。
如果我在Spring Boot应用程序的@RestController
类中的方法中调用完全相同的代码,则该代码不再起作用,并且继续显示以下内容:
2019-05-23 10:16:51.075 ERROR 26045 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.amazonaws.services.lambda.model.AWSLambdaException: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. (Service: AWSLambda; Status Code: 403; Error Code: InvalidSignatureException; Request ID: 7fb1ecf0-7d3b-11e9-89c2-8775f15f937d)] with root cause
com.amazonaws.services.lambda.model.AWSLambdaException: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. (Service: AWSLambda; Status Code: 403; Error Code: InvalidSignatureException; Request ID: 7fb1ecf0-7d3b-11e9-89c2-8775f15f937d)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1712) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1367) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1113) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:770) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532) ~[aws-java-sdk-core-1.11.534.jar:na]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512) ~[aws-java-sdk-core-1.11.534.jar:na]
我当然尝试在构建客户端时添加凭据,
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("accessKey", "secretKey")))
该库的版本和Java都相同。 Spring Boot的版本为2.1.3.RELEASE(如果可能的话)。
答案 0 :(得分:0)
我有同样的问题。
我解决了直接在项目的httpclient
中添加pom.xml
。
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
Spring Boot依赖于该库的另一个版本。
您需要将aws-java-sdk-core
库所需的模块版本添加到pom.xml
。