Open MartijnHarmenzon opened 4 years ago
What happens when you use the "Test" feature of API Gateway?
I've had similar issues before, and the CORS error is usually emanating from the API Gateway layer, instead of the Lamdba layer. By using the "Test" feature in the API Gateway, the Lambda function gets invoked directly. Set your headers to how you'd normally have it and take a look at the results.
I have the exact same problem, regardless whether it is a POST or GET method.
I have put a minimal repro under: https://github.com/Misza13/cors-gzip-repro
The line that breaks the solution (the way to gzip content is taken straight from Chalice tutorial) is:
app.api.binary_types.append('application/json')
With it, API gateway logs will show on OPTIONS call:
(6a6ea518-2ca3-436f-b74b-6e3f61c39dfb) Execution failed due to configuration error: Unable to transform request
Without it, OPTIONS works but the actual GET/PUT will fail and yield this error:
[ERROR] Runtime.MarshalError: Unable to marshal response: b'\x1f\x8b\x08\x00J\xafS^\x02\xff\xabV\xcaH\xcd\xc9\xc9W\xb2RP*\xcf/\xcaIQ\xaa\x05\x00"\xae\xa3\x86\x12\x00\x00\x00' is not JSON serializable
Damned if you do, damned if you don't.
@MartijnHarmenzon Have you been able to resolve/work around this?
Oh and @ricky-sb the "Test" feature works without issues. Problems arise whenever you call the API with any external tool such as Postman or fetch
in the browser.
@Misza13 'Glad' to hear that I am not the only one with this issue. Unfortunately, I do not have a satisfying solution. I converted my request from POST to GET and included the POST parameters within the GET url. Not the way I would like, but it works.
@MartijnHarmenzon I think I got to understand the issue, lead by a fix mentioned in https://forums.aws.amazon.com/message.jspa?messageID=785296#785356 - created a simple PR that fixes the OPTIONS integrations created by Chalice. I have already managed to get my API to work the way I intended based on my fork.
Thanks for looking into this, I'll take a look at the PR shortly.
I am running into a CORS error and can not seem to find out why. After testing I think it has something to do with either CORS, headers,
app.api.binary_types.append("application/json")
, or a combination. Can someone help? I have searched the web for a couple of hours, but can not seem to find the answer.My Chalice app code:
My JavaScript code: