1

I'm using a service that runs outside of my premises that uses a websocket API to emit events that occur inside it. Let's call this wss://X.

I have a web app that currently runs a websocket client that connects to wss://X and if it receives an event fires a call back that does some book keeping (update a database, queue a notification).

I'd like to keep this separate from my web app (different developer, separate logic etc.). I'd like to have something I'm called a listener for wss://X which will just sleep till something comes up on this connection and if so, do something and then shut down.

This seems like a good candidate for AWS lambda. Short running functions that do book keeping based on events but I'm not sure how I can trigger them. Someone suggested AWS API gateway but I don't know how to make it listen (rather than bind) to a certain URL and then trigger lambda functions based on events that it receives. If this is not possible, what can I use on AWS that would solve this problem for me?

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169

1 Answers1

2

You can't use Lambda for long-running tasks (refer to Is it possible to subscribe to a WebSocket in a serverless fashion using AWS?).

Considering that the listener needs to be long-running as it must listen to events from wss://X, an alternative that I can think of is to start an EC2 instance that runs code which continuously listens to wss://X and does the operations that you want.

noninertialframe
  • 568
  • 1
  • 10
  • 24
  • 1
    Thanks. That's basically what I've done. I was planning to use lambda as the event handler. It wouldn't be the *listener* but the function that gets fired when the listener receives an event. I wanted to know if the listener could be API gateway. – Noufal Ibrahim Oct 09 '21 at 04:20