Google Cloud Load Balancer to a Cloud Function directly?
I'm trying to send traffic from a Google Cloud Load Balancer (LB) directly to a Cloud Function.
My Cloud Function has an HTTP URL trigger
and if I hit that URL from a browser it works, so all I need is a rule on the load balancer to proxy that URL.
So the setup would be:
Load Balancer -> Cloud Function -> Cloud Storage
However from looking at the LB backend configuration, it seems that the only allowed options are either a service (eg a Virtual Machine) or a Bucket (ie Cloud Storage):
load balancer config screenshot
Am I missing something or is there simply no way of sending traffic directly from a Cloud Load Balancer to a Cloud Function?
Solution 1:
I believe the approach detailed in your question is what cannot be done. From what I understood, you are looking to serve a static website and if any files are renamed/moved, you would like the cloud function to manage the routing.
On top of Http triggers, Cloud functions do offer the Cloud Storage trigger, which allow you to act based on the Cloud storage bucket behavior. This way, whenever there's a change in the bucket containing all static files, you could act according to it and use the REST backendServices and/or forwardingRules to modify the Load Balancer configurations and set up any existing static file(s) to be routed correctly and route all other urls to a default 301 static file.
Hope this helps.
Solution 2:
For future readers, as of July 2020, the HTTPS Load Balancer can now handle routing to Cloud Function, Cloud Run & AppEngine. See below announcement from Google:
https://cloud.google.com/blog/products/networking/better-load-balancing-for-app-engine-cloud-run-and-functions