Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Google Cloud function: python os.getenv('HOME') returns /root !

Dear All,

In the console shell provided my $HOME shows /home/googleid but in the cloud function python script it shows as /root - i want to create/delete files in my actual $HOME via this cloud function.

Please suggest how can i achieve this instead of hardcoding my googleid in the code if i can set (externally) & use any environment variable for any work.

thanks

ars07

0 1 898
1 REPLY 1

Hello,

The environment variables in Cloud Function and the actual $HOME in your project are different, because they're two different entities given that the Cloud Function instance could be seen like its own stripped down container.

I would like to know more about what you're exactly trying to achieve, and what do you mean by "create/delete" files in the "/home/googleid" path. 

If your main issue is about being able to create custom environment variables, we don't currently support that. However a public issuetracker feature request[1] has been created for it, which you can follow and star to follow its progress and click on +1 to reflect the importance of the FR. Although, please note that it has no ETA and its realization is not guaranteed at the moment.

One workaround for custom environment variables to be used by your Cloud Function could be to create a JSON file with the "custom environment variable" that you wish to have and store it in Cloud Storage. Then, you could retrieve the values from said file with your Cloud Function instance.

Hopefully it helps, let me know if you'd like to discuss this further.

Regards,

 

[1] https://issuetracker.google.com/186452227