2
votes

I have a local NodeJS application that I am building locally.

I want the local application to point to the local Datastore Emulator (not the production Cloud Datastore).

I followed the instructions on this page... However, the application is still pointing to the CLOUD datastore (not my local datastore). I confirmed this because data is showing up in the Datastore Entities page on App Engine.

According to this page, https://cloud.google.com/datastore/docs/tools/datastore-emulator all that should be required is to set environment variables by running this command:

$(gcloud beta emulators datastore env-init)

I confirmed the environment variables are being set correctly. Why is my application still pointing to the Cloud Datastore and not the local emulator?

myusername$ $(gcloud beta emulators datastore env-init)
myusername$ gcloud beta emulators datastore env-init
export DATASTORE_DATASET=projectname
export DATASTORE_EMULATOR_HOST=localhost:8081
export DATASTORE_EMULATOR_HOST_PATH=localhost:8081/datastore
export DATASTORE_HOST=http://localhost:8081
export DATASTORE_PROJECT_ID=projectname

Here is the output when running the emulator:

myname$ gcloud beta emulators datastore start
WARNING: Reusing existing data in [/Users/myname/.config/gcloud/emulators/datastore].
Executing: /Users/myname/google-cloud-sdk/platform/cloud-datastore-emulator/cloud_datastore_emulator start --host=localhost --port=8081 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown /Users/myname/.config/gcloud/emulators/datastore
[datastore] Oct 30, 2017 3:47:46 PM com.google.cloud.datastore.emulator.CloudDatastore$FakeDatastoreAction$8 apply
[datastore] INFO: Provided --allow_remote_shutdown to start command which is no longer necessary.
[datastore] Oct 30, 2017 3:47:46 PM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub <init>
[datastore] INFO: Local Datastore initialized:
[datastore]     Type: High Replication
[datastore]     Storage: /Users/myname/.config/gcloud/emulators/datastore/WEB-INF/appengine-generated/local_db.bin
[datastore] Oct 30, 2017 3:47:47 PM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub load
[datastore] INFO: The backing store, /Users/myname/.config/gcloud/emulators/datastore/WEB-INF/appengine-generated/local_db.bin, does not exist. It will be created.
[datastore] Oct 30, 2017 3:47:47 PM io.gapi.emulators.netty.NettyUtil applyJava7LongHostnameWorkaround
[datastore] INFO: Unable to apply Java 7 long hostname workaround.
[datastore] API endpoint: http://localhost:8081
[datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run:
[datastore] 
[datastore]   export DATASTORE_EMULATOR_HOST=localhost:8081
[datastore] 
[datastore] Dev App Server is now running.
[datastore] 
1
I am having exactly the same issue, in the python environment. Apparently, the SDK is not taking the env vars into account. Very weird.Bruno Ripa
I suggest upvoting my question so it might get a bit more attention. I still have not found a solution.pengz
I managed to have things working. Basically, you still need to provide real credentials to your app, inspite of the guides that tell you to just setup environment variables. After you have done this, having the environment variables pointing to the right values does the trick. Any code you want to show ?Bruno Ripa

1 Answers

0
votes

I've found setting DATASTORE_EMULATOR_HOST and DATASTORE_PROJECT_ID to be sufficient.

Perhaps it's finding other environment variables that point to the cloud?

Have you tried clearing the GOOGLE_APPLICATION_CREDENTIALS environment variable?