gpt4 book ai didi

java - 从 Spring Boot 运行时出现 AWSLambdaException 和 InvalidSignatureException

转载 作者:行者123 更新时间:2023-11-30 01:50:24 25 4
gpt4 key购买 nike

我有一个 super 简单的 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 如果这可能有帮助。

最佳答案

我也有同样的问题。我解决了直接在项目的 pom.xml 中添加 httpclient 的问题。

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>

Spring boot 依赖于该库的另一个版本。您需要将aws-java-sdk-core库所需的模块版本添加到pom.xml

关于java - 从 Spring Boot 运行时出现 AWSLambdaException 和 InvalidSignatureException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56272400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com