google-cloud-platformgoogle-cloud-run

Google Cloud Run API - accessing endpoint internally


Bear with me, I am still on training wheels with GCP

Scenario being

  1. I have a Cloud Run instance serving an API (to be consumed internally)
  2. A middleware running on Cloud Compute instance serving an API. This utilises API served by (1)

(2) needs to access (1)

I'm trying to figure out how to discover the internal DNS name or IP, so that the middleware (2) can be configured to access Cloud Run served API (1)

Intention being to create templates (environment config files) so that I can eventually automate the deployment of all layer.


Solution

  • With Cloud Run, you can't know before the first deployment the URL of the service. The pattern is

    https://<serviceName>-<projectHash>.<region>.run.app
    

    You can also have optionally a tag at the beginning, but it's not important here.

    The bad part is the project Hash can't be calculated before the deployment (or I donc know the hash formula). Thus it's impossible to register in a DNS the URL in advance of the deployment.


    However, if you use tools like terraform, you can get, as output, the URL of the service after the deployment and then register it in your DNS, as CNAME (Cloud Run is a managed service, you haven't a static IP).


    You can also use the CLoud Run API to request the list of services on a project, pick the service that you want and get the URL of the service (get request to the service API)


    A last word before you hit the wall, you talk about internal endpoint. Cloud Run url is public, and public only. Therefore, your middleware need to access to the internet to be able to request Cloud Run.

    If your middleware is deployed on the same project, you can set the Cloud Run service ingress to internal to allow only resources from the VPCs of the current project to access to Cloud Run service.

    But the URL is still public and you need an internet access to resolve and to access it.