- Newest
- Most votes
- Most comments
You're correct in your understanding of the current limitations regarding binary frames in API Gateway's WebSocket integration. Let me clarify the situation based on the available information:
-
Receiving binary frames from clients: API Gateway WebSocket APIs do not currently support binary frames in incoming message payloads. If a client sends a binary frame, API Gateway will reject it and disconnect the client with code 1003.
-
Sending binary frames to clients: The situation for sending binary data from the server to the client is indeed less straightforward. While there isn't explicit support for sending binary frames directly over WebSockets, there are workarounds available.
For your specific case, using a non-proxy integration with the integration response content handling strategy set to CONVERT_TO_BINARY is a step in the right direction. However, the UTF-8 error you're encountering suggests that the binary data is still being sent as a text frame rather than a binary frame.
To work around these limitations, here are some approaches you can consider:
-
Base64 encoding: Instead of trying to send actual binary frames, you can have your Lambda function return base64-encoded data. On the client side, you would need to decode this base64 string back into binary data. This approach ensures that all communication remains text-based, which is fully supported by API Gateway WebSockets.
-
Custom encoding: You could implement a custom encoding scheme that represents your binary data as text. This might be more efficient than base64 for certain types of data.
-
Chunked transfer: For large binary payloads, you could split the data into smaller chunks, send them as text frames, and reassemble them on the client side.
-
Alternative protocols: If binary frame support is crucial and cannot be worked around, you might need to consider alternative solutions like using WebRTC data channels or a different WebSocket server implementation.
In conclusion, while API Gateway WebSockets do not natively support binary frames in either direction, you can still transfer binary data by encoding it as text. The limitation is that the WebSocket frames themselves must always be text frames. If you need true binary frame support, you may need to explore alternative solutions outside of API Gateway WebSockets.
Sources
Binary media types for WebSocket APIs in API Gateway - Amazon API Gateway
WebSocket APIs: Showcasing a Practical Networking Solution | AWS Spatial Computing Blog
answered 2 years ago
Relevant content
asked a year ago
asked 2 years ago
asked 4 years ago
