Hands On and Viewing Examples

Length: 00:11:46

Lesson Summary:

It is time to go hands-on to create a Spanner instance, and we will also populate another instance using Python scripts in order to exam a more complete database example.

The below steps ran from Cloud Shell will create a Spanner instance and populate Singer and Album data for you.

  1. Link Google Cloud documentation to follow along with for the Python example:

  2. Clone the GitHub repository to run scripts, and browse to the correct directory:

    • git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

    • cd python-docs-samples/spanner/cloud-client

  3. Create a Python environment and install dependencies:

    virtualenv env
    source env/bin/activate
    pip install -r requirements.txt
  4. Create a Spanner instance named test-instance:

    • gcloud spanner instances create test-instance --config=regional-us-central1 --description="Test Instance" --nodes=1
  5. Create a database and insert data using the Python scripts from our GitHub clone:

    • python snippets.py test-instance --database-id example-db create_database

    • python snippets.py test-instance --database-id example-db insert_data

  6. Run a query to read the values of all columns from the Albums table:

    • gcloud spanner databases execute-sql example-db --instance=test-instance --sql='SELECT SingerId, AlbumId, AlbumTitle FROM Albums'

This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More