Reputation: 321
Inside my code, how can I get the public URL of my Cloud Run project?
Let's suppose that my Cloud Run is hosted at:
https://my-cloud-run-a7jtmot2uw-uc.a.run.app
And I want to get this information in my code.
For example. I am using App Engine and I do the same thing in Python with the following code:
public_url = "https://%s.uc.r.appspot.com" % os.environ["GOOGLE_CLOUD_PROJECT"]
Upvotes: 2
Views: 3065
Reputation: 4913
From your code you can make an API call to Method: namespaces.services.get and parse status.url of the returning Service object.
Upvotes: 2
Reputation: 143
I'm worried that you can't do that this way. But you can create env variable with this url and get in in the code
PUBLIC_URL=https://my-cloud-run-a7jtmot2uw-uc.a.run.app
and in code
public_url = "os.environ["PUBLIC_URL"]
edit: There is similar question and you can check if hiting endpoint will return you URL in managed cloud run Google cloud run: Can a service know its own url?
Upvotes: 1