'AWS API gateway returning error code 400 from server, but on postman/curl returns 200
I have setup an API gateway to call lambda using lambda integration.
However when I try to call the API gateway from a server it says error 400 bad request. But it works when making curl / postman POST requests from my mac.
I'm seeing 400 error in the API gateway dashboard, so its not even hitting Lambda, so we can rule out lambda issues.
I tried the following and did not fix the issue:
- EntityTooLarge - I tried 1kb payload size
- Enabling CORS
- Validation rules
- No resource policy
- No authorizors
- Tried ANY and POST resource
- no certificates
I'm stuck on figuring out why this is not working, can anyone help?
Solution 1:[1]
There is likely something different between the requests curl / Postman and your server are sending. You should compare the headers being included in the request (Postman adds quite a few automatically), and check query parameters for GET requests and request bodies for POST and PATCH requests. I faced this problem with some GET requests when trying to setup a SCIM integration with Okta, and it turned out that Okta was including some query parameters that were failing model validation for my API. If some application is sending these requests, you should consider the possibility that the requests it is sending are not what you expected.
The cause of your error is most likely going to be different, but it is probably due to some discrepancy between the two requests. To troubleshoot, you can turn on verbose logging in API Gateway which will log the full request and response with headers, query parameters, and body.
- Open the API Gateway console
- Select your API and API stage
- Select the Logs/Tracing tab
- Check the box for Enable CloudWatch Logs and then check Log full requests/responses data
- Deploy your API
- Go to Resources
- Select the Actions dropdown
- Choose Deploy API
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Corey |
