Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

gen2 cloud function on load balancer

Hello Guys,

I am wondering why my gen2 cloud function cannot be found on my load balancer. I get a 404 response when I try to call it from my static website, which is deployed on the same load balancer.

The exact same setup works properly with a gen1 cloud function.

On my load balancer, I create a network endpoint group:

gcloud compute network-endpoint-groups create #{@cloud_function_endpoint_group} \
--cloud-function-name=#{@cloud_function_name} \
--network-endpoint-type=serverless
 
A backend service:
gcloud compute backend-services create #{@cloud_function_service} \
--protocol=HTTP \
--session-affinity=NONE 
 
 Then I add the endpoint group to the service:
gcloud compute backend-services add-backend #{@cloud_function_service} \
--network-endpoint-group=#{@cloud_function_endpoint_group} \
--network-endpoint-group-region=#{@region} 
 
And finally, I simply add the backend service to the path matcher, which is available from /cloud-function of the same url.
 
Is there something I am missing here ? Or is the solution something else I overlooked ?
 
Thanks,
Best Regards
Solved Solved
0 2 1,963
1 ACCEPTED SOLUTION

Cloud Functions of 2nd generation are deployed as Cloud Run services. Given this, you could try creating your NEG using the --cloud-run-service flag instead.

Keep in mind the service must also be in the same project and region as the Network Endpoint Group. 

You could also check this guide which deploys a 2nd gen. Cloud Function in a load balancer, and does so using it as a Cloud Run service.

View solution in original post

2 REPLIES 2

Cloud Functions of 2nd generation are deployed as Cloud Run services. Given this, you could try creating your NEG using the --cloud-run-service flag instead.

Keep in mind the service must also be in the same project and region as the Network Endpoint Group. 

You could also check this guide which deploys a 2nd gen. Cloud Function in a load balancer, and does so using it as a Cloud Run service.

Thanks a lot, simply changing "--cloud-function-name" to "--cloud-run-service" fixed the issue.