- Newest
- Most votes
- Most comments
The issue you're experiencing seems to be related to how the API Gateway is processing the incoming request body. The error message suggests that the API Gateway is attempting to parse the request body as JSON, but it's receiving form-encoded data instead.
Here are a few things to check and potential solutions:
-
Content-Type Header: Ensure that the client sending the request is setting the Content-Type header to 'application/x-www-form-urlencoded'. If this header is not set correctly, API Gateway might default to trying to parse the body as JSON.
-
API Gateway Configuration: Double-check your API Gateway configuration to make sure it's set up to handle form-encoded data. In the Integration Request settings, verify that the Content Handling is set to "Convert to Text (if needed)".
-
Lambda Proxy Integration: If you're using Lambda Proxy integration, the raw body is passed directly to your Lambda function. In this case, you might need to parse the form-encoded data within your Lambda function instead of relying on API Gateway to do the transformation.
-
Mapping Template: While your mapping template looks correct for handling form-encoded data, ensure it's actually being applied. Check that the Content-Type header in the Method Request matches exactly what you've set for the mapping template (including case sensitivity).
-
API Gateway Changes: AWS occasionally updates API Gateway, which could potentially affect how certain configurations work. Check if there have been any recent updates or changes to API Gateway that might impact your setup.
-
Testing: Try testing with a simple form-encoded payload (e.g., "key1=value1&key2=value2") to see if the issue persists. This can help isolate whether the problem is with the specific payload or the overall configuration.
If none of these solve the issue, you might need to contact AWS support for further assistance, as there could be an underlying issue with the API Gateway service or your specific configuration.
Remember to thoroughly test any changes in a non-production environment before applying them to your live API.
Sources
Tutorial: Create a REST API with a Lambda non-proxy integration - Amazon API Gateway
Tutorial: Create a calculator REST API with two AWS service integrations and one Lambda non-proxy integration - Amazon API Gateway
Relevant content
- asked 9 months ago