By Kelsey Hightower, Developer Advocate
The general availability of Cloud Spanner is really good news for developers. For the first time, you have direct access to horizontally-scaling, cloud-native infrastructure that provides global transactions (think apps that involve payments, inventory, ticketing, or financial trading) and that defaults to the “gold standard” of strong/external consistency without compromising latency. Try that with either a traditional RDBMS or non-relational database.
Thanks to the GCP Free Trial that offers $300 in credits for one year, you can get your feet wet with a single-node Cloud Spanner cluster over the course of a couple weeks. Here’s how to do that, using the Spanner API via gcloud. (Click here for the console-based approach.)
In Cloud Console, go to the Projects page and either create a new project or open an existing project by clicking on the project name.
Open a terminal window and set your project as the default for gcloud. Do this by substituting your project ID (not project name) with the command:
gcloud config set project [MY_PROJECT_ID]
Enable billing for your project.
Enable the Cloud Spanner API for your project.
Set up authentication and authorization (Cloud Spanner uses OAuth 2.0 out of the box) with the following command:
gcloud auth application-default login
API client libraries now automatically pick up the created credentials. You need to run the command only once per local user environment. (Note: This approach is suitable for local development; for production use, you’ll want to use a different method for auth.)
Next, create a single-node instance:
gcloud spanner instances create test-instance
–config=regional-us-central1
–description=”Test Instance” –nodes=1
Finally, create a database. To create a database called test-db:
gcloud spanner databases create test-db –instance=test-instance
Alternatively, you can download sample data and interact with it using the language of your choice.
That’s it — you now have your very own Cloud Spanner database. Again, your GCP credit should allow you to run it cost-free for a couple weeks. From there, you can download sample data and interact with it using the language of your choice.
Quelle: Google Cloud Platform
Published by