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.
1 Answer
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.
-
This is very helpful, thank you. Using the Cloud FUnctions Python Library only works if things were deployed as a Cloud Function it seems and not as a cloud run service. In my case I have a cloud run service. Is there a cloud run api that can do this?– yamboCommented Mar 26 at 23:41