Reputation: 14616
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 want a Lambda function to be 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)
Upvotes: 3
Views: 2840
Reputation: 1
You can solve this with Cloudflare Serverless WebSocket API https://developers.cloudflare.com/workers/examples/websockets/#write-a-websocket-client All you need is to make a call to your AWS backend API from serverless WebSocket Cloudflare function and pass received data along! This technically outside of AWS realm but fits your requirements.
Upvotes: 0
Reputation: 681
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.
Upvotes: 3
Reputation: 7998
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.
Upvotes: 4