How to use the same G. Cloud Datastore for apps in standard and flexible environments?

73 views
Skip to first unread message

Juan Antonio Fernández Sánchez

unread,
Feb 16, 2017, 7:59:32 AM2/16/17
to Google App Engine

I'm working in a project that use two apps, one deployed in App Engine standard environment and other in flexible env.


One service of the app in the standard env and the app in the flex env. must be access to Google Cloud Datastore.

If I use in local the emulated datastore that run the dev_server in standard environment, the app in the flex env. can't access to this datastore and neither use the ndb ORM library like the service in standard env.


So, to have consistency in the way to access to data, I don't what solution would be better to solve this.

I've been thinking if I could use Google Cloud SDK (gcloud tool) to run emulators datastore and access to this using Cloud Datastore Cient Libraries ( instead of Google Datastore NDB Client Library ) in both apps (to use exactly the same way to connect) I think that this way is most easy to develop after in cloud platform.


I'm finding some problems to connect with this emulated datastore and I would like to know if my approach is good to follow fighting with the problems or change to another way or idea to run my entire project in local.


Any help or idea will be welcome.

Nick (Cloud Platform Support)

unread,
Feb 28, 2017, 4:14:29 PM2/28/17
to Google App Engine
Hey Juan,

You're right to point out that our documentation could be better here. We're currently working on expanding the documentation on the Datastore emulator. Now, as to your main question:

google-cloud-datastore

You can use the google-cloud-datastore library to interact with the datastore emulator from both standard and flexible environment dev_appserver apps.

environment variables

Just be sure to set the environment variables properly by running $(gcloud beta emulators datastore env-init). Be sure to run the command exactly like that, with the $() 
included, since this will tell the shell to run the commands which are actually output by gcloud beta emulators datastore env-init. The commands, which you could also examine and then run yourself, one by one, are going to look like this:

export DATASTORE_DATASET=my-project-id
export DATASTORE_EMULATOR_HOST=localhost:8715
export DATASTORE_EMULATOR_HOST_PATH=localhost:8715/datastore
export DATASTORE_HOST=http://localhost:8715
export DATASTORE_PROJECT_ID=my-project-id

and you're good to go

When this is done, the python client library linked above will connect to the local emulator. See the documentation on the client library (the link was above) for the details of coding.

a small note about the datastore admin viewer in dev

Currently, the dev_appserver.py admin panel (localhost:8000 usually) "datastore" section does not connect properly to the emulator. This is documented in this Public Issue Tracker issue I've just filed, and you can star that issue to receive updates. I hope this has been helpful to you, and feel free to ask any further questions you have. I'll be happy to assist.

Cheers,

Nick
Cloud Platform Community Support
Reply all
Reply to author
Forward
0 new messages