Cloud Run get public URL

Viewed 1038

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"]
2 Answers

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?

Related