Search code examples
javascriptangularwebsocketamazon-cloudfront

Cloudfront with Websocket connection


I have been reading over the documentation here on connection a websocket service with a client through a cloudfront distribution but I am unable to understand where the upgrade to the websocket protocol will occur. Will the upgrade need to be handled by the server or will the cloudfront distribution handle changing the protocol to wss and respond with the connection?


Solution

  • The answer to my problem was a simple change to the Cloudfront Distribution.These headers needed be added so that my server (using express/express-ws) would receive the http request with the correct headers to validate the session and return with the upgraded protocol response for the client. (This was out of the box with express-ws and rxjs). I can post a coded example if needed.

    1. Sec-WebSocket-Key
    2. Sec-WebSocket-Version
    3. Sec-WebSocket-Protocol