8

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?

Panda Coder
  • 81
  • 1
  • 3
  • Unfortunately you will need to stand something up between the loadbalancer and the URL trigger. Maybe look at using appengine for this. It scales to 0, so can be pretty cost efficient. What is the purpose of sitting the LB in front of the cloud function? – Murcurio May 28 '18 at 06:20
  • I'm using cloud storage to serve static websites (https://cloud.google.com/storage/docs/hosting-static-website). It works great but the problem is that when files are renamed/moved, URL changes, and link breaks. To workaround that issue I want all requests to hit a cloud function (catchall rule `/.* -> cloud function`). That function would handle 301 redirects if any (based on a mapping table, `URL source -> URL target`) and if no redirects, read/serve the HTML pages from the cloud storage. I HTTP headers would be set so those HTML pages get cached on the client. – Panda Coder May 29 '18 at 12:12

2 Answers2

4

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

emirhosseini
  • 141
  • 2
2

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.

Jean
  • 31
  • 4