Can lambda connect to external websocket?

Hi!

I thought it was not possible, since lambda times out after 15 minutes and it’s mostly for short burst functions. But I’m not so sure anymore.

Can it connect to for example external exchange websocket? Or would I need to have EC2 instance for that?

You can connect, but as you pointed out, it will timeout after 15 minutes.

For this type of work, I suggest using Fargate - much less to manage than with EC2.

hmm Okay, I’ve never heard of Fargate [I’m a beginner] Does it integrate with lambda easily?

Fargate allows to run a docker container, for how long you need it. Just keep in mind it takes around minute to start it.
You can start container from lambda, you can make trigger lambda from container, with usual AWS SDK calls.

On your case fargate will replace lambda

I would need a constant stream, non stop 24/7 instead of invoking lambda every X seconds/minutes.

I already have a whole app written in Lambda, I’m just wondering if for some of the jobs Fargate would be a better choice. Thanks for giving me a direction, I’ll read more about it.

Dzięki!

Can lambda connect to external websocket?

Yes. But the “direct” use case is only useful for short “request reply” situations where Lambda makes a request to something listening on websockets, then lambda reads the reply and shuts off. Lambda isn’t useful for “run this all the time” websockets server.

On the other hand, you CAN fire off a lambda when you get a message using either API GW or IOT. (I think they both do it, but at least one can do it.) This is useful for the OTHER side of request reply, where a browser makes a request over WebSockets and lambda runs and generates a reply.

You can if you use Api Gateway Websockets with Lambda: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html

I don’t want to create a websocket, please read my post :slight_smile:

Ah sorry my bad