arrow_back

Create and Manage Cloud Spanner Instances: Challenge Lab

登录 加入
访问 700 多个实验和课程

Create and Manage Cloud Spanner Instances: Challenge Lab

实验 1 小时 30 分钟 universal_currency_alt 1 个积分 show_chart 入门级
info 此实验可能会提供 AI 工具来支持您学习。
访问 700 多个实验和课程

GSP381

Google Cloud self-paced labs logo

Overview

In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to complete the tasks on your own! An automated scoring system (shown on this page) will provide feedback on whether you have completed your tasks correctly.

When you take a challenge lab, you will not be taught new Google Cloud concepts. You are expected to extend your learned skills, like changing default values and reading and researching error messages to fix your own mistakes.

To score 100% you must successfully complete all tasks within the time period!

This lab is recommended for students who have enrolled in the Create and Manage Cloud Spanner Instances skill badge. Are you ready for the challenge?

Topics tested

  • Create a Cloud Spanner instance.
  • Create a Cloud Spanner database.
  • Create a tables in your database.
  • Load simple datasets into tables
  • Load a complex dataset.
  • Add a new column to an existing table.

Target audience

The content of this challenge lab will be most applicable to Cloud Spanner DBAs. This lab is designed to test the abilities of students who have completed the Create and Manage Cloud Spanner Databases quest.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details pane.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details pane.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field. Navigation menu icon and Search field

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

  2. Click through the following windows:

    • Continue through the Cloud Shell information window.
    • Authorize Cloud Shell to use your credentials to make Google Cloud API calls.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Challenge Scenario

In your role as the corporate Database Administrator, you have been tasked with standing up a new Cloud Spanner database for your company's Banking Operations group. You have been provided a list specifcations for this database related to tables datasets to load.

Task 1. Create a Cloud Spanner instance

  1. Your first task is to create an instance.

  2. You may complete this step using the Cloud Console or the gcloud CLI.

  3. Your instance must have following attributes:

Item Value
Name banking-ops-instance
Region
Allocate Compute Capacity Unit - Nodes // Quantity - 1



An example gcloud CLI command to create an instance is as follows:

gcloud spanner instances create my-sample-instance \ --config=regional-{{{primary_project.default_region|Region}}} \ --description="Sample Instance" \ --nodes=1
  1. Click Check my progress to verify the objective.
Create an instance

Task 2. Create a Cloud Spanner database

  1. Your next task is to create a database.

  2. You may complete this step using the Cloud Console or the gcloud CLI.

  3. Your database must have following attribute:

Item Value
Name banking-ops-db



An example gcloud CLI command to create a database is as follows:

gcloud spanner databases create my-sample-db \ --instance=my-sample-instance
  1. Click Check my progress to verify the objective.
Create a database

Task 3. Create tables in your database

  1. Your database must have a total of four (4) tables - Portfolio, Category, Product, and Customer.

  2. The tables must be defined as listed below.

An example DDL command to create a table is as follows:

CREATE TABLE Sample ( SampleId INT64 NOT NULL, SampleName STRING(MAX) ) PRIMARY KEY (SampleId);

Table: Portfolio

Primary Key: PortfolioId

Column Datatype
PortfolioId INT64 NOT NULL
Name STRING(MAX)
ShortName STRING(MAX)
PortfolioInfo STRING(MAX)



Table: Category

Primary Key: CategoryId

Column Datatype
CategoryId INT64 NOT NULL
PortfolioId INT64 NOT NULL
CategoryName STRING(MAX)
PortfolioInfo STRING(MAX)



Table: Product

Primary Key: ProductId

Column Datatype
ProductId INT64 NOT NULL
CategoryId INT64 NOT NULL
PortfolioId INT64 NOT NULL
ProductName STRING(MAX)
ProductAssetCode STRING(25)
ProductClass STRING(25)



Table: Customer

Primary Key: CustomerId

Column Datatype
CustomerId STRING(36) NOT NULL
Name STRING(MAX) NOT NULL
Location STRING(MAX) NOT NULL



Task 4. Load simple datasets into tables

  1. Three of your tables, Portfolio, Category, and Product, will be loaded with simple, low-volume datasets.

  2. You may employ any method to load these tables.

Note: The data elements provided are ordered to match the order of the columns of the corresponding table.

An example DML command to load a single row into a table is as follows:

INSERT INTO Sample (SampleId, SampleName) VALUES (1, "Banking");

Table: Portfolio

1, "Banking", "Bnkg", "All Banking Business" 2, "Asset Growth", "AsstGrwth", "All Asset Focused Products" 3, "Insurance", "Insurance", "All Insurance Focused Products"

Table: Category

1,1,"Cash" 2,2,"Investments - Short Return" 3,2,"Annuities" 4,3,"Life Insurance"

Table: Product

1,1,1,"Checking Account","ChkAcct","Banking LOB" 2,2,2,"Mutual Fund Consumer Goods","MFundCG","Investment LOB" 3,3,2,"Annuity Early Retirement","AnnuFixed","Investment LOB" 4,4,3,"Term Life Insurance","TermLife","Insurance LOB" 5,1,1,"Savings Account","SavAcct","Banking LOB" 6,1,1,"Personal Loan","PersLn","Banking LOB" 7,1,1,"Auto Loan","AutLn","Banking LOB" 8,4,3,"Permanent Life Insurance","PermLife","Insurance LOB" 9,2,2,"US Savings Bonds","USSavBond","Investment LOB"
  1. Click each Check my progress to verify the objectives.
Create and Load Tables

Task 5. Load a complex dataset

  1. You will load the Customer table with a much larger set of data.

  2. A file named Customer_List_500.csv contains 500 rows of data and is located in the following public Cloud Storage bucket. You may reference or download it as necessary.

gsutil URI

gs://cloud-training/OCBL375/Customer_List_500.csv

HTTP URL

https://storage.googleapis.com/cloud-training/OCBL375/Customer_List_500.csv
  1. You may recall from the lab Cloud Spanner - Loading Data and Performing Backups that a few options exist to load larger datasets. These include using Dataflow or a client library in Batch mode. You may choose to create simple insert statements. The decision is yours but you must load all 500 rows.

  2. Utilize any method that you prefer to load the 500 row datafile. Some methods will require edits to the datafile which will require downloading it to your local machine. Please be sure to make a backup file if you choose that option.

  3. Note: if you use Dataflow should ensure that you specify the Regional Endpoint and reset the Dataflow API via the following gcloud command:

gcloud services disable dataflow.googleapis.com --force gcloud services enable dataflow.googleapis.com
  1. Also if you use a Dataflow template you will be required to provide a Mainfest file named manifest.json. Below is a sample manifest.json that you can use to guide creation of a file appropriate for loading the Customer table.
Note: This sample cannot be used as is, you must update it accordingly.

Note:

{ "tables": [ { "table_name": "TABLE_NAME", "file_patterns": [ "gs://BUCKET/FOLDER/FILENAME.SUFFIX" ], "columns": [ {"column_name" : "UPDATE_COLUMN1", "type_name" : "UPDATE_DATATYPE" }, {"column_name" : "UPDATE_COLUMN2", "type_name" : "UPDATE_DATATYPE" }, {"column_name" : "UPDATE_COLUMN3", "type_name" : "UPDATE_DATATYPE" } ] } ] }
  1. Click Check my progress to verify the objective.
Load Customer table

Task 6. Add a new column to an existing table

  1. As part of your DBA responsibilities you are required to add a new column called MarketingBudget to the Category table.

  2. The column MarketingBudget must have a datatype of INT64.

  3. Adding a new column is accomplished by a DDL command. You may issue the DDL via a gcloud command, the Cloud Console, or client library call.

An example gcloud CLI command to add a column to a table is as follows:

gcloud spanner databases ddl update my-sample-db \ --instance=my-sample-instance \ --ddl='ALTER TABLE Sample ADD COLUMN SampleValue INT64;'
  1. Click Check my progress to verify the objective.
Add Column

Congratulations!

In this lab, you created a Cloud Spanner instance and database, created tables, loaded data, and performed DDL operations on a table.

Create and Manage Cloud Spanner Instances skill badge

Earn Your Next Skill Badge

This challenge lab is part of the Create and Manage Cloud Spanner Instances skill badge. Completing this skill badge course earns you the badge above, to recognize your achievement. Share your badge on your resume and social platforms, and announce your accomplishment using #GoogleCloudBadge.

This skill badge course is part of Google Cloud’s Database Engineer learning path. If you have already completed the other skill badge courses in this learning path, search the catalog for other skill badge courses in which you can enroll.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated July 17, 2024

Lab Last Tested July 17, 2024

Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

准备工作

  1. 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
  2. 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
  3. 在屏幕左上角,点击开始实验即可开始

使用无痕浏览模式

  1. 复制系统为实验提供的用户名密码
  2. 在无痕浏览模式下,点击打开控制台

登录控制台

  1. 使用您的实验凭证登录。使用其他凭证可能会导致错误或产生费用。
  2. 接受条款,并跳过恢复资源页面
  3. 除非您已完成此实验或想要重新开始,否则请勿点击结束实验,因为点击后系统会清除您的工作并移除该项目

此内容目前不可用

一旦可用,我们会通过电子邮件告知您

太好了!

一旦可用,我们会通过电子邮件告知您

一次一个实验

确认结束所有现有实验并开始此实验

使用无痕浏览模式运行实验

请使用无痕模式或无痕式浏览器窗口运行此实验。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。