This page walks you through the setup steps required to use the Cloud Spanner API with the Google Cloud CLI, client libraries, and Spanner drivers.
If you want to use Spanner with the Google Cloud console, see Quickstart using the console.
Before you begin
Your development machine should have the following installed:
- The gcloud CLI, which includes setting up the Google Cloud CLI (download).
Set up a Google Cloud project
-
Go to the Projects page in the Google Cloud console.
- Create a new Google Cloud project, or open an existing project by clicking on the project name.
-
Open a terminal window, and set your project as the default project for the Google Cloud CLI, replacing
MY_PROJECT_ID
with your project ID (not your project name):gcloud config set project MY_PROJECT_ID
-
Make sure that billing is enabled for your Google Cloud project.
You can also learn about Spanner pricing.
-
Enable the Cloud Spanner API for the project.
Note: If you use a service account in a different project to access your Spanner instance, you need to enable the Spanner API in both projects.
Set up authentication and authorization
Spanner uses OAuth 2.0 for API authentication and authorization.
To run your code locally during development and testing, use the Google Cloud CLI 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 Google Cloud CLI
Now that you've set up your development environment and authentication, run the
gcloud
command-line tool to interact with
Spanner:
gcloud spanner instance-configs list
You should see a list of the Spanner instance configurations that your project can access, including regional, dual-region, and multi-region configurations. For more information, see the Instances overview.
You've completed the setup!
What's next
Learn how to use the Cloud Client Libraries and drivers to create a Spanner instance, database, tables, and indexes. Then store, query, and read data in Spanner.
- Getting started with Spanner in C++
- Getting started with Spanner in C#
- Getting started with Spanner in Go
- Getting started with Spanner in Java
- Getting started with Spanner in JDBC
- Getting started with Spanner in Node.js
- Getting started with Spanner in PHP
- Getting started with Spanner in Python
- Getting started with Spanner in Ruby
- Getting started with Spanner in REST
- Getting started with Spanner in gcloud