1

In Google shell which is a part of Google cloud, I set environment variable GOOGLE_APPLICATION_CREDENTIALS because It is need it for PHP NLP project [info: https://cloud.google.com/natural-language/docs/quickstart-client-libraries#client-libraries-install-php]. My project worked fine, but I notice that variable GOOGLE_APPLICATION_CREDENTIALS lasts on my sistem only one day. This is my third time that I am setting it. My project doesn't work when I am missing required variable. Am I doing something wrong?

EDIT: It is default OS (Debian) when you create new App on Google App engine. When I type help in Google shell I get info with: Your 5GB home directory will persist across sessions, but the VM is ephemeral and will be reset approximately 20 minutes after your session ends. No system-wide change will persist beyond that.

dsesto
  • 7,864
  • 2
  • 33
  • 50
Slit
  • 491
  • 1
  • 7
  • 20

2 Answers2

2

You are completely right, Cloud Shell is running on an ephemeral instance that resets some minutes after the session has ended, reason why you are losing the content of the environment variable you mentioned.

The documentation about limitations in Cloud Shell clearly states that it is intended for interactive use only, and any non-interactive session or intensive usage can be automatically terminated with (or without) a warning.

Therefore, and understanding from your question that you have a background script that is working with Cloud Natural Language, I would strongly advise you to move to a "real" instance of Compute Engine, in which you will have much more control about what is happening. This will allow more flexibility and you will be able to use a bigger machine type, given that Cloud Shell runs on a g1-small GCE instance which, in general, is not enough to run an application. Also, depending on your use case, you may even consider App Engine.

That being said, I have found that when constructing the LanguageClient instance, you may also not use Application Default Credentials and, instead, use the keyFile or keyFilePath variables (explained in the PHP Client Library reference) to pass the path to the JSON key directly to your code, instead of reading it from the environment variable.

dsesto
  • 7,864
  • 2
  • 33
  • 50
  • Thank you for answer. One more thing, am I going to have problems with key when I deploy an app through gcloud on my vm instance? – Slit May 29 '18 at 15:59
  • I am not sure what do you mean by *deploy an app through gcloud on my VM instance*. If you mean deploying an App Engine application from a GCE instance, you will need to set up credentials accordingly. But, in general, this will happen with any GCP-related product that you are using, you will have to set up the necessary credentials in order to use it (Service Accounts, API keys...). – dsesto May 29 '18 at 16:02
  • In any case, feel free to open a new question for that if it is a different topic that is worth its own question, and [accept/upvote the answer if it was helpful for you](https://stackoverflow.com/help/someone-answers). – dsesto May 29 '18 at 16:02
1

Lets assume you are using Linux, make sure that:

  • It is Linux. When you create App on App engine it is some kind of Debian. – Slit May 29 '18 at 12:33
  • When I type help in Google shell, I notice sentence: Your 5GB home directory will persist across sessions, but the VM is ephemeral and will be reset approximately 20 minutes after your session ends. No system-wide change will persist beyond that. – Slit May 29 '18 at 12:42
  • Are you using a 'preemptible' instance? Also if you have a way to set an initialization script, you could put the credentials file in the home directory, and set the environment variable in the initialization script – Leonardo Trocato May 29 '18 at 12:47
  • I am using default Debian that you get when you open Shell (top right corner) in App engine section on Google Cloud Platform. – Slit May 29 '18 at 12:49