Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a serverless websocket client on AWS

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)

like image 309
Vingtoft Avatar asked Feb 14 '26 20:02

Vingtoft


2 Answers

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.

like image 163
udalmik Avatar answered Feb 16 '26 18:02

udalmik


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.

like image 41
Rovelcio Junior Avatar answered Feb 16 '26 18:02

Rovelcio Junior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!