Search code examples
google-cloud-datastoregoogle-cloud-platformgoogle-cloud-functions

How can I get current projectId inside Google Cloud Functions?


The question is simple. I need projectId in order to establish connection insde Google Cloud Function. I found the documentation where it said, that projectId is optional parameter and will be checked from GCLOUD_PROJECT, but on deployed function it didn't work.

So it is the question now how can I get the projectId env variable in order to pass it as argument for Datastore connection instance, or what should be done to not pass this id and establish connection with datastore inside Google Cloud Function?

Update 1

I found that I actually can get variable from process.env.GCLOUD_PROJECT, just like any other env.variable. But, know is the last question, is it actually possible to use @google-cloud/datastore without any configuration object?


Solution

  • As I wrote in update 1 we can get all the information about environment from the process.env variable.

    And the second question about configuration object for @google-cloud/datastore, it actually can work without any options. It will trying to fetch all required parameters from environment variables. So, it didn't work beacuase of error in my code.