This page describes how to activate the Google Cloud Datastore API, the quotas associated with this API, how to enable billing, and how to set a spending limit. The activation process varies based on your existing setup and environment.
Enable Cloud Datastore for your project
To use Cloud Datastore, your project requires the following:
The Cloud Datastore API must be enabled for the project. You can enable the API for an existing project, or create a new project and then enable the API.
Your project requires an active App Engine application. Confirm that your project has an active App Engine app from the App Engine dashboard:
You can also meet these requirements by completing the Cloud Datastore Quickstart. The quickstart will enable the Cloud Datastore API and create an App Engine app for you.
Accessing Cloud Datastore from App Engine
To get started with Cloud Datastore and App Engine, see one of the following language-specific pages:
|App Engine Standard Environment||App Engine Flexible Environment|
Cloud Datastore permissions for App Engine
App Engine apps can access Cloud Datastore instances in the same project by default. Each App Engine app uses an App Engine default service account to manage access to GCP services like Cloud Datastore. By default, the App Engine default service account has the Project Editor IAM role, which includes full read and write access to Cloud Datastore.
You can modify the IAM permissions of your App Engine default service account, but your app may lose access to Cloud Datastore unless you assign an IAM role with the required Cloud Datastore permissions. The Cloud Datastore Owner and Cloud Datastore User IAM roles, for example, grant read and write access to Cloud Datastore.
If you delete your App Engine default service account, you must restore your App Engine service account to access Cloud Datastore.
Accessing Cloud Datastore from a Compute Engine instance
This section shows how to activate and access the Cloud Datastore API from a Compute Engine VM instance in a new or existing project.
Enable the Google Compute Engine API for the project you selected or created in the previous step.
Enable the Compute Engine API
Make sure that billing is enabled for your project.
- Create a Compute Engine instance.
- In the Google Cloud Platform Console, go to the VM Instances page.
- Click the Create instance button.
- In the Identity and API access section, set Access scopes to provide access for Datastore. Either click Allow full access to all Cloud APIs to grant access to all Google Cloud APIs, or click Set access for each API, click the dropdown for Cloud Datastore, and then click Enabled to grant access to Cloud Datastore.
- Click the Create button to create the instance.
- Confirm that your instance is running.
- To use this new Compute Engine instance, connect to it using your browser.
- If you haven't already done this, install the
gcloudcommand-line tool and set up
Add a Google Compute Engine instance and start it, following the instructions for starting an instance in the Google Compute Engine documentation. Specify the project ID, the instance name, and the
datastorescope as shown here, where
[YOUR_PROJECT_ID]is the ID of the project you created previously and
[YOUR_INSTANCE_NAME]is the name you want to use for your Compute Engine instance:
export PROJECT_ID=[YOUR_PROJECT_ID] export INSTANCE_NAME=[YOUR_INSTANCE_NAME] gcloud compute instances create $INSTANCE_NAME --project $PROJECT_ID --scopes datastore
Confirm that your instance is running.
- To use this new Compute Engine instance, connect to it using
Accessing Cloud Datastore from another platform
This section shows how to activate and access the Cloud Datastore API from an external application running on a platform outside of Google Cloud Platform.
- Enable Cloud Datastore for your project.
- Go to the Create service account key page.
- Click the drop-down box below Service account, then click New service account.
- Enter a name for the service account in Name.
- Use the default Service account ID or generate a different one.
- Select JSON in Key type.
- Click Create.
- Upon successful creation, your browser will download the private key. The GCP Console provides a prompt that displays the private key file name. Note the file name so you can locate it, then click Close to dismiss the prompt.
- Your Service Account is the Email address displayed under the Service Account section.
- Your Private Key is the file you just downloaded.
Quotas and billing
A certain amount of free quota is available, as described in Pricing and Quota. This means you aren't required to enable billing to get started or to use Cloud Datastore up to the free quota limits. However, if you need more resources than is provided by the free quota, you must enable billing and set a spending limit for your project.
Enabling billing and setting a spending limit
The spending limit is a daily limit: it sets the maximum dollar amount of resources you will be charged for each day. After this limit is reached, no further costs will be incurred, but also, no further billable Cloud Datastore operations will be allowed. You'll need to specify a spending limit because the initial default spending limit is always 0, which means by default you cannot exceed the free quota, even with billing enabled.
Cloud Datastore resources are part of App Engine resources. The spending limit for App Engine resources are set in the App Engine Application settings.
To enable billing:
Make sure that billing is enabled for your project.
To set a spending limit:
- Go to the Application settings.
Go to the Application settings
- Click Edit and specify a spending limit.
- Click Save.
The spending limit only applies to App Engine resources, which includes Cloud Datastore, for the selected project:
- You may still be charged for other Google Cloud Platform resources.
- If you have multiple projects, you may want to set the spending limit for each project.
When you increase the daily spending limit, the new limit takes effect immediately.
For more information, see Spending Limits.