admin 管理员组文章数量: 1086019
I'm using the AWS SDK v2 in my Java program to send a request to an API Gateway I've hosted. I'm seeing some unexpected errors where I'm receiving a 403 Forbidden response from my gateway, but only in cases where I'm providing a request body via contentStreamProvider
. If I remove the request body, the request passes my authorizer and is able to hit my lambda function. I'm really stumped on what the issue is.
The below code returns a 403 Forbidden Error from the APIG
Map<String, String> payload = new HashMap<String, String>();
payload.put("A", "foo");
payload.put("B", "bar");
String requestBody = objectMapper.writeValueAsString(payload);
SdkHttpFullRequest request = SdkHttpFullRequest.builder()
.method(SdkHttpMethod.POST)
.protocol("https")
.host(API_ENDPOINT)
.encodedPath(PATH)
.appendHeader("Content-Type", "application/json")
.contentStreamProvider(() -> new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)))
.build();
Aws4Signer signer = Aws4Signer.create();
Aws4SignerParams signerParams = Aws4SignerParams.builder()
.signingName("execute-api")
.signingRegion(Region.US_EAST_1)
.awsCredentials(credentialsProvider.resolveCredentials())
.build();
SdkHttpFullRequest signedRequest = signer.sign(request, signerParams);
HttpExecuteRequest req = HttpExecuteRequest.builder()
.request(signedRequest)
.build();
The below modification (removing the contentStreamProvider) passes the authorizer.
SdkHttpFullRequest request = SdkHttpFullRequest.builder()
.method(SdkHttpMethod.POST)
.protocol("https")
.host(API_ENDPOINT)
.encodedPath(PATH)
.appendHeader("Content-Type", "application/json")
.build();
Any idea what the issue could be?
本文标签: aws lambdaAPI Gateway Access Errors with Java SDKStack Overflow
版权声明:本文标题:aws lambda - API Gateway Access Errors with Java SDK - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744070191a2528342.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论