Cloud function: distinguish between local and online run

I am working with cloud functions, and I develop locally on my machine.

How can I distinguish between local and online run? I (used to) use the env var GCP_PROJECT but it is now removed in new runtime environments. I need this distinction for a bunch of reasons, one for all to load secrets from file if on local env.
Do you have best-practice on it to suggest?

I know about the existence of the functions framework but, I think, doesn't solve my problem.

Thank you

0 2 155
2 REPLIES 2

Hi @davidgerva ,

Currently, there's no official documentation for getting the "The current Google Cloud project ID" for newer runtimes as it will vary depending on what programming language you're using but I have found out some solution/workaround that can help with your issue. I would suggest checking out this Stackoverflow thread for more information.

Thank you.

Dear @marcanthonyb 

thank you very much for your reply. However, I am not looking to retrieve the project_id, I am looking for a way to distinguish between local and online run. I want to know when I am running inside GCP or outside.

Thank you for your effort,
David