2

I have a WebSocket that I'm subscribing to and when an event comes in, I want to trigger a Google Cloud Function. Is this possible?

For example, I'm listening to https://alpaca.markets/docs/api-documentation/api-v2/streaming/

And whenever I get trade_updates, I want to run a function on Google cloud Functions

Shamoon
  • 41,293
  • 91
  • 306
  • 570

1 Answers1

1

All trigger types for Cloud Functions are listed here: https://cloud.google.com/functions/docs/calling

Web Sockets are not directly supported as a trigger type.

The closest I can think of is setting up an architecture like this:

overview of the architecture

So here you have some code listening to the web socket and then triggering Cloud Functions through Pub/Sub or one of the other supported trigger types.

Pylinux
  • 11,278
  • 4
  • 60
  • 67
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • So then doesn’t that middle piece of code (that’s long running) take away the whole point of using a FaaS? – Shamoon Jun 03 '20 at 16:22
  • 1
    Partially yes. But you should be able to keep this code very lightweight, especially if you do asynchronous events only (so not waiting for a response). That way a single compute instance could handle *a lot* of events. You could also run it on another auto-scaling infrastructure, but it'd still be auto-scaling containers rather than pure FaaS. – Frank van Puffelen Jun 03 '20 at 18:32