google-cloud-platformgoogle-cloud-functionsgoogle-cloud-run

How to get the URL of a Cloud Run Function from within a Cloud Run Function


I have a python cloud run function and I want to get the URL of another cloud run function programatically. I want to avoid hard coding the URL if possible. I need the URL so that I can create a task that has this other functions url as the HTTP url, and then send that task to a task queue.


Solution

  • Yes, it is possible to obtain the URL of another Cloud Run function from a Cloud Run function itself.

    If you know the name of the Cloud Run function, you can use the Deterministic URL approach. This allows you to determine the URL of the function by simply filling in the necessary details. This information is available even before the function is created.

    To get the URL programmatically, you can utilize the Cloud Functions Python library get_function to retrieve the details of another Cloud Run function. However, ensure that the Cloud Run function's identity service account has the Cloud Functions Viewer Role when making the request using this library, as it requires run.services.get or cloudfunctions.functions.get permissions.