Socket.io-client: Socket.io client connection through AWS Api Gateway

Created on 12 Jun 2020  ·  4Comments  ·  Source: socketio/socket.io-client

Hello. I am trying to create a connection like this: socket.io-client -> AWS Gateway API.
While trying to connect from socket.io client to an AWS Gateway API, connection can't be established.
It stucks with a status '101 switching protocols' for a few seconds, then throws 'disconnected' event and tries to reestablish connection, and the process repeats infinitely.
This doesn't happen with native WebSockets or 'ws' library though, everything connects like it should.
I think issue has something to do with how socket.io client and server sides interact with each other by exchanging certain messages which may not be generated on the AWS side of things.
So my question is: is that even possible to establish a connection like this without using proxies:
socket.io-client -> AWS Api Gateway -> socket.io(node.js),
or it always has to be Socket.io-client -> socket.io(node.js)?

Amazon AWS documention was used for configuring gateway: https://aws.amazon.com/blogs/compute/announcing-websocket-apis-in-amazon-api-gateway/
It uses standart $connect, $disconnect and $default routes, but instead of lambda its nodejs backend. The issue though is only on the client side.

question

Most helpful comment

@Sairyss is there an update on this?

@JerryLeeCS I ended up using native WebSockets on a client side and $connect, $disconnect and $default routes on a backend side. I didn't find any solution to make it work with Socket.io. Seems like Socket.io connections from the frontend are not supported by AWS Gateway API, it just refuses to connect.

All 4 comments

@Sairyss is there an update on this?

@Sairyss is there an update on this?

@JerryLeeCS I ended up using native WebSockets on a client side and $connect, $disconnect and $default routes on a backend side. I didn't find any solution to make it work with Socket.io. Seems like Socket.io connections from the frontend are not supported by AWS Gateway API, it just refuses to connect.

It seems it's possible: https://stackoverflow.com/a/56364967

@darrachequesne If I read that link/so post correctly he is using an EC2 server running SocketIO server? It's a little unclear. I am in the same boat - ws works fine but not socket io - no connection at all. Using default websocket server provided by aws api gateway (through serverless) .

Was this page helpful?
0 / 5 - 0 ratings