- Newest
- Most votes
- Most comments
Based on the AWS documentation, when you configure binary media types as "/" in API Gateway, the API treats all content types as binary data. This configuration affects how API Gateway handles request and response payloads across all integration types, including Mock integrations.
The "/" wildcard configuration is specifically recommended for scenarios where you cannot control the order of Accept header values, such as requests from browsers. API Gateway uses the first Accept header from clients to determine if a response should return binary media, and when binary media types are set to "/", the API interprets responses as binary payloads.
For Mock integrations specifically, the integration response can be configured with content handling strategies. When dealing with binary payloads in non-proxy integrations, you can set the integration response's contentHandling property to control how the payload is processed - for example, converting from binary to base64-encoded text using CONVERT_TO_TEXT.
The issue you're experiencing likely stems from the fact that with "/" configured as a binary media type, API Gateway is attempting to handle the Mock integration response as binary data, but the Mock integration is returning a text/JSON response. This mismatch in content handling expectations could cause the 500 error you're seeing.
To resolve this while maintaining support for binary content in other endpoints, you may need to configure the contentHandling property on your Mock integration response appropriately, or reconsider whether "/" is necessary for your specific use case. If you only need binary support for specific endpoints (like those serving images or files through Lambda proxy integrations), you might configure specific binary media types (like "image/png" or "application/octet-stream") rather than the wildcard, allowing Mock integrations to continue functioning normally for text responses.
Sources
Binary media types for WebSocket APIs in API Gateway - Amazon API Gateway
Binary media types for REST APIs in API Gateway - Amazon API Gateway
Relevant content
- asked 2 years ago
