Set Up

This page walks you through the setup steps required to use the Cloud Spanner API.

If you want to use Cloud Spanner without using the API, see Quickstart Using the Console.

Before you begin

Your development machine should have the following installed:

Set up a GCP Console project

  1. In the Google Cloud Platform Console, go to the Projects page.
  2. Go to the Projects page
  3. Create a new GCP Console project or open an existing project by clicking on the project name.
  4. Open a terminal window and set your project as the default project for the gcloud command-line tool, by substituting your project ID (not project name) as follows:
  5. gcloud config set project [MY_PROJECT_ID]
    
  6. Make sure that billing is enabled for your project.

    Learn how to enable billing

    For information about Cloud Spanner pricing, see Pricing.
  7. Enable the Cloud Spanner API for the project.
    Enable the Cloud Spanner API

Set up authentication and authorization

Cloud Spanner uses OAuth 2.0 for API authentication and authorization.

To run your code locally during development and testing, use the Google Cloud SDK (the gcloud command-line tool) along with Application Default Credentials. At a command prompt, run:

gcloud auth application-default login

After you authenticate using the gcloud auth application-default login command, API client libraries that use the application default credentials automatically pick up the created credentials. You need to run the command only once per local user environment.

Run the gcloud command-line tool

Now that you've set up your development environment and authentication, run the gcloud command-line tool to interact with Cloud Spanner:

gcloud spanner instance-configs list

You should see a list of the Cloud Spanner instance configurations that your project can access, including regional and multi-region configurations. Learn more about these in Instances.

You've completed the setup!

What's next

Learn how to use the Google Cloud Client Libraries to create a Cloud Spanner instance, database, tables, and indexes. Then store, query, and read data in Cloud Spanner.

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Spanner Documentation