Using AWS, I want my backend to listen to a websocket connection from an external server (that I do not control). This websocket connection emits market data.
Each time the external server pushes data onto the websocket, I wan't a Lambda function to get triggered. To be clear: In this situation, AWS acts as the client.
Is it possible to achieve this functionality in a serverless manner (without using EC2)?
I looked into AWS IoT pub/sub and API Gateway/w WS, but these services do not act as the client (I might be wrong though)
CodePudding user response:
I think we are loosing the benefits of serverless model here, as we need permanent tcp connection opened by WS client. EC2 looks like a good match in general.
If we know the period of times we need to listen for market data, then one of the options could be to trigger Fargate instance by CloudWatch event, listening for messages for some time and then closing the connection and Fargate instance. The pricing/benefits against EC2 will depend on the range of time we need to listen for incoming data.
CodePudding user response:
Currently, no AWS product seems to provide outgoing websocket connections.
Here's a question from some time ago asking for the same functionality.
All of API Gateway (and other related services) documentation regarding websockets only describes incoming (server) connections.
Your better option would in fact be to host your own websocket client application on an EC2 instance.