logo image

Running Google Cloud Datastore in local for development

Views: 157

This tutorial explains you how to setup and run Google's Google Cloud Datastore in local environment so that you can you can develop and test your code locally. Follow the below steps to run your AppEngine application with the local datastore

1. Installing Google Cloud Datastore

Make sure you have gcloud SDK setup done already. Once you have the gcloud with you run the following command to install Google Cloud Datastore locally

gcloud components install gcd-emulator

This will install you Google Cloud Datastore locally and on successful installation, you will see logs similar to the following

MacBook-Pro:experimantal$ gcloud components install gcd-emulator

Your current Cloud SDK version is: 178.0.0
Installing components from version: 178.0.0

│             These components will be installed.              │
│                Name               │    Version    │   Size   │
│ Cloud Datastore Emulator (Legacy) │ v1beta3-1.0.0 │ 38.1 MiB │

For the latest full release notes, please visit:

Do you want to continue (Y/n)?  Y

╠═ Creating update staging area                             ═╣
╠═ Installing: Cloud Datastore Emulator (Legacy)            ═╣
╠═ Creating backup and activating new installation          ═╣

Performing post processing steps...done.                                                                                                                                                                           

Update done!


2. Starting the emulator

You can run the following command to start Google Cloud Datastore in your local

gcloud beta emulators datastore start

3. Setting up the environment variables

Run the following command to set the environment variables, so that your all will use the local datastore running instead the Google Cloud Datastore server

gcloud beta emulators datastore env-init

This outputs something like following

MacBook-Pro:experimantal$ gcloud beta emulators datastore env-init
export DATASTORE_EMULATOR_HOST=localhost:8081
export DATASTORE_EMULATOR_HOST_PATH=localhost:8081/datastore
export DATASTORE_HOST=http://localhost:8081

4. Go ahead and start your application

Now you are all set to use the Datastore in the local environment.