Skip to content

websocket connection

0

my process is frontend reactnative coonect the API gatewat websocket it connect to the lambda1 whenever user can login audio chunks will continously come to the backend without any storing in lambda1 is recive chunks and i create a lambda2 in this lambda2 invoke the lambda1 in this lambda2 that chunks taken it will convert the text format by using LLM model everything i will done but the issue is websocket error Enter image description here

1 Answer
1
Accepted Answer

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:

  1. 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 contentHandlingStrategy property to CONVERT_TO_BINARY to convert the payload from base64-encoded string back to binary.

  2. For responses containing binary data from your LLM processing, you can set the integration response's contentHandlingStrategy property to CONVERT_TO_TEXT to convert binary payloads to base64-encoded strings.

  3. 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

answered a year ago

EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.