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?