0

Why can't I call my AWS API Gateway REST API using a GET request with an application/json HTTP body? CloudFront returns an error:

"Bad request".

The GET method is configured with proxy integration for the Lambda backend, so should just proxy the request through.

However, calling the POST method, with the same headers and HTTP body, yields a result.

enter image description here

$ curl -XGET --json '{"n": 5}' -H 'Authorization: Bearer foo' -H 'x-gateway-authorization: Bearer bar' 'https://a5t0qb2tfg.execute-api.eu-west-1.amazonaws.com/prod/fib'                                                                                                                                                                                                                                                                                                                                         git:(main|✚18…7
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: I4wmI1bt3ddj5uScRwkIU-ONFAiyQCZoYm3BIYMH6LR5QHpK1cM2aw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>%
$ curl -XPOST --json '{"n": 5}' -H 'Authorization: Bearer foo' -H 'x-gateway-authorization: Bearer bar' 'https://a5t0qb2tfg.execute-api.eu-west-1.amazonaws.com/prod/fib'                                                                                                                                                                                                                                                                                                                                        git:(main|✚18…7
{"result": 5, "job_id": "55dc052c-2b08-486e-87b6-462abcf24e96"}%

1 Answer 1

2

Because the title mentions that you are using Cloudfront, you may be hitting a Cloudfront limitation.

If a viewer GET request includes a body, CloudFront returns an HTTP status code 403 (Forbidden) to the viewer.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! But how can I opt out of using CloudFront? I use the aws_apigateway.RestApi class from the AWS CDK

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.