Using the gcloud Tool to Test Applications and Manage Indexes

You can use the gcloud command-line tool to test your application locally and to manage indexes for your production Google Cloud Datastore instance. This page describes the typical workflow for these activities.

The gcloud tool supports the following workflow:

  1. Create local support for a Cloud Datastore instance, including directory, required files, and project ID.
  2. Start up the Cloud Datastore emulator, which provides local emulation of the production Cloud Datastore environment.
  3. Generate index definitions from your application's queries to the emulator.
  4. Upload manually created or generated index definitions to your production Cloud Datastore instance.
  5. Delete unused indexes from your production Cloud Datastore instance.

The development workflow using the command-line tool

The following is the typical workflow using the gcloud tool:

  1. Start the Datastore emulator.

  2. Set environment variables so your application knows it is using the emulator.

  3. Start your application and test it against the emulator. You need to run the queries your application uses against the emulator in order to generate indexes for your production Cloud Datastore instance.

  4. Upload the generated indexes with the create-indexes command, passing in the path to your local index.yaml file, as in the following example:

    gcloud datastore create-indexes ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
    

    The example path assumes you have not set a specific directory for the data-dir option. If you have set a specific directory, modify the path to use the path to your index.yaml file.

  5. Remove environment variables so your application knows it is using the production Cloud Datastore instance.

  6. Run your application against your production Cloud Datastore instance.

  7. Over time, you might no longer use some of the indexes. You can delete unused indexes from your production Cloud Datastore instance by removing them from your local index.yaml file and then invoking the cleanup-indexes command:

    gcloud datastore cleanup-indexes ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
    

    If you have set a specific directory for the data-dir option, modify the path in the example to use the path to your index.yaml file.

What's next

Send feedback about...

Cloud Datastore Documentation