- Newest
- Most votes
- Most comments
The issue you're experiencing with UTF-8 character encoding in API Gateway is likely related to how the API is configured to handle binary media types and content type conversions. Here are a few steps you can take to address this problem:
-
Configure binary media types: Add "application/json" to the binaryMediaTypes list on your RestApi resource. This tells API Gateway to treat JSON payloads as potentially containing binary data.
-
Set content handling: For your integration, set the contentHandling property to CONVERT_TO_TEXT. This ensures that API Gateway correctly handles the UTF-8 encoded JSON string.
-
Lambda function response: Make sure your Lambda function is returning the response in the correct format, including the proper content type header. The response should look like this:
{ "isBase64Encoded": false, "statusCode": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": JSON.stringify({ your: "response data" }) }
- API Gateway method response: Ensure that the Content-Type header is included in the method response of your API.
By implementing these configurations, you should be able to properly handle UTF-8 characters in your JSON payloads without the encoding issues you're currently experiencing. The repeated encoding problem you're seeing (where "£" becomes "£" and then "ã") is typically a sign of multiple incorrect UTF-8 encodings being applied, which these steps should resolve.
If you're still experiencing issues after applying these configurations, you may need to review your client-side code to ensure it's sending the data with the correct encoding as well.
Sources
Content type conversions in API Gateway - Amazon API Gateway
Lambda proxy integrations in API Gateway - Amazon API Gateway
Binary media types for REST APIs in API Gateway - Amazon API Gateway
answered 2 years ago
Relevant content
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 2 years ago
