- Newest
- Most votes
- Most comments
Based on the error message in your screenshot, it appears you're encountering an issue with binary frames in your WebSocket connection. API Gateway WebSocket APIs currently do not support binary frames in incoming message payloads. When a client sends a binary frame, API Gateway rejects it and disconnects the client with code 1003, which is what you're experiencing.
For your audio streaming use case, here are some workarounds:
-
Text-encoded binary data: Instead of sending raw binary audio chunks, convert them to base64-encoded strings on the frontend and send them as text frames. In your Lambda integration, you can set the
contentHandlingStrategyproperty toCONVERT_TO_BINARYto convert the payload from base64-encoded string back to binary. -
For responses containing binary data from your LLM processing, you can set the integration response's
contentHandlingStrategyproperty toCONVERT_TO_TEXTto convert binary payloads to base64-encoded strings. -
Implement chunking: Break your audio data into smaller pieces and send them as text frames, then reassemble them on the server side.
Since you're working with audio chunks that need to be processed by an LLM, the WebSocket API is a good choice for real-time, two-way communication. Just remember that all WebSocket frames must be text frames when working with API Gateway, so any binary data needs to be properly encoded.
Also note that authorization in WebSocket APIs is performed at connection time via the $connect route, and this authorization applies to the entire connection. If you need additional authorization logic for specific message types after connection, you'll need to implement that in your Lambda functions.
Sources
Binary media types for WebSocket APIs in API Gateway - Amazon API Gateway
API Gateway Websocket Binary Frames | AWS re:Post
API gateways - Is it possible to create API gateways with streaming response support? | AWS re:Post
API Gateway WEBSOCKET- How to use multiple authorizers for each route of an websocket? | AWS re:Post
Relevant content
asked a year ago
asked a year ago
- AWS OFFICIALUpdated 2 years ago
