建立 Spanner 免費試用執行個體和範例應用程式

本快速入門導覽課程說明如何使用 Spanner 免費試用執行個體和範例應用程式。詳情請參閱 Spanner 免費試用執行個體總覽

開始免費試用執行個體

只要擁有 Google 帳戶,並在專案中啟用 Cloud Billing,即可建立 Spanner 90 天免費試用執行個體。除非您選擇將免費試用執行個體升級為付費執行個體,否則我們不會向您收費。

您可以使用 Google Cloud 控制台或 Google Cloud CLI 建立免費試用執行個體。

事前準備

控制台

  1. 前往 Google Cloud 控制台的「Spanner」頁面。

    前往 Spanner

  2. 選取或建立 Google Cloud 專案 (如果尚未建立)。

  3. 如果專案已啟用 Cloud Billing,請前往下一節的「建立免費試用例項」。

    如果專案未啟用 Cloud Billing,請連結現有的 Cloud Billing 帳戶,或建立新的 Cloud Billing 帳戶。Google 會使用這項付款資訊驗證您的身分。除非您將 Cloud Billing 帳戶升級為付費帳戶,並將 Spanner 免費試用執行個體升級為付費執行個體,否則我們不會向您收取 Spanner 執行個體的費用。

    a. 按一下「前往帳單」

    「必須啟用計費功能才能繼續使用 Spanner」對話方塊的螢幕截圖,並醒目顯示「前往計費」按鈕。

    b. 然後按一下「連結至帳單帳戶」

    這項專案沒有帳單帳戶的頁面螢幕截圖,並醒目顯示「連結帳單帳戶」按鈕。

    c. 按照步驟建立帳單帳戶,然後連結至專案。

    d. 為專案啟用 Cloud Billing 後,請前往「Spanner」頁面。

    前往 Spanner

    e. 按一下「開始免費試用」,然後前往下一節「建立免費試用例項」。

  4. 選用:如果您先前已在專案中建立 Spanner 執行個體,系統會顯示下列「Spanner Instances」(Spanner 執行個體) 頁面。

    按一下「開始免費試用」

    Spanner 執行個體頁面的螢幕截圖,並醒目顯示「建立免費執行個體」。

gcloud

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Install the Google Cloud CLI.

  3. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  4. To initialize the gcloud CLI, run the following command:

    gcloud init
  5. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  6. Make sure that billing is enabled for your Google Cloud project.

  7. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

  8. Install the Google Cloud CLI.

  9. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  10. To initialize the gcloud CLI, run the following command:

    gcloud init
  11. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  12. Make sure that billing is enabled for your Google Cloud project.

  13. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

建立免費試用執行個體

控制台

下列步驟說明如何使用Google Cloud 控制台建立免費試用執行個體。

在「建立免費試用的執行個體」頁面上,執行下列操作:

  1. 輸入要顯示在 Google Cloud 控制台的「Instance name」(執行個體名稱)。執行個體在 Google Cloud 專案中不得重複。
  2. 輸入可永久識別執行個體的執行個體 ID。 Google Cloud 專案中的執行個體 ID 也不得重複。執行個體 ID 設定後即無法變更。
  3. 從「Region」下拉式選單中選取設定位置。

    執行個體設定會決定系統要將執行個體儲存及複製到哪個地理位置。請注意,這個設定清單比付費執行個體可用的清單小得多。如要查看免費試用執行個體可用的區域設定清單,請參閱「可用的執行個體設定」。如需所有可用執行個體設定的完整清單,請參閱地區、雙區域和多區域設定

  4. 按一下「建立免費執行個體」

    建立免費試用執行個體後,系統會提示您啟動逐步教學課程,繼續學習及探索 Spanner,瞭解如何使用範例應用程式建立資料庫。詳情請參閱「開始使用範例應用程式」。

gcloud

如要建立免費試用執行個體,請使用 gcloud spanner instances create 指令。

gcloud spanner instances create INSTANCE_ID \
   --instance-type=free-instance --config=INSTANCE_CONFIG \
   --description=INSTANCE_DESCRIPTION

更改下列內容:

  • INSTANCE_ID:專案中唯一的永久 ID。 Google Cloud 執行個體 ID 設定後即無法變更。
  • INSTANCE_CONFIG:執行個體設定的永久 ID,定義執行個體的地理位置。您可以透過下列區域執行個體設定建立免費試用執行個體:

    • 美洲:regional-us-central1 (愛荷華州)、regional-us-east1 (南卡羅來納州)、regional-us-east4 (北維吉尼亞州)、regional-us-east5 (哥倫比亞)
    • 歐洲:regional-europe-west1 (比利時)、regional-europe-west3 (法蘭克福)
    • 亞洲:regional-asia-northeast1 (東京)、regional-asia-south2 (德里)、 regional-asia-southeast2 (雅加達)
  • INSTANCE_DESCRIPTION:顯示於Google Cloud 控制台中的執行個體名稱。執行個體名稱在Google Cloud 專案中不得重複。

舉例來說,如要使用地區執行個體設定 regional-us-east5 建立名稱為 trial-instance 且顯示名稱為 Trial Instance 的免費試用執行個體:

gcloud spanner instances create trial-instance --config=regional-us-east5 \
  --instance-type=free-instance --description="Trial Instance"

開始使用範例應用程式

Spanner 提供開放原始碼的範例應用程式,協助您開始使用 Spanner 免費試用執行個體。範例應用程式包含由 Spanner 資料庫支援的後端 gRPC 服務,以及將流量導向該服務的工作負載產生器。

您可以使用 Google Cloud CLI 存取範例應用程式。

gcloud

  1. 完成「gcloud 設定」一文中說明的步驟,包含建立與設定預設的 Google Cloud 專案、啟用 Cloud Spanner API,以及設定 OAuth 2.0 以取得使用 Cloud Spanner API 的驗證憑證。

    執行 gcloud auth application-default login 指令,使用驗證憑證設定本機開發環境。

  2. 執行 gcloud spanner samples run 指令,下載範例應用程式,並啟動指定範例應用程式的後端 gRPC 服務和工作負載產生器:

    gcloud spanner samples run APPNAME --instance-id INSTANCE_ID
    
  3. 如要瞭解詳情,以及查看範例應用程式的其他可用指令清單,請參閱 gcloud CLI 說明文件

升級免費試用執行個體

下列步驟說明如何升級免費試用例項。

控制台

  1. 前往 Google Cloud 控制台的「Spanner Instances」(Spanner 執行個體) 頁面。

前往「Instances」(執行個體) 頁面

  1. 按一下免費試用執行個體的名稱。

  2. 在「執行個體總覽」頁面上,按一下「編輯執行個體」或「編輯以升級」

「執行個體總覽」頁面和「編輯以升級」按鈕的螢幕截圖

  1. 在「Update instance name」(更新執行個體名稱) 欄位中,輸入付費執行個體更適用的名稱 (如適用)。

  2. 選取「升級選項」。你可以選取下列任一選項:

    • 立即升級
    • 在試用期結束後,自動升級至 Enterprise 版本的完整版本
    • 稍後提醒我

    「摘要」部分會說明所選升級付費執行個體的運算和儲存空間費用。

  3. 按一下「儲存」,即可升級免費試用執行個體。

gcloud

如要將免費試用執行個體升級為付費 Enterprise 版執行個體,並沿用相同的執行個體設定,請執行下列gcloud spanner instances update指令:

gcloud spanner instances update INSTANCE_ID --instance-type=provisioned

刪除執行個體

主控台

  1. 前往 Google Cloud 控制台的「Spanner Instances」(Spanner 執行個體) 頁面。

    前往「Instances」(執行個體) 頁面

  2. 按一下您要刪除的執行個體名稱。

  3. 在「執行個體總覽」頁面中,按一下「刪除執行個體」

  4. 請按照操作說明來確認您要刪除的執行個體。

  5. 點選「刪除」。

gcloud

如要刪除免費試用執行個體,請使用下列 gcloud spanner instances delete 指令:

gcloud spanner instances delete INSTANCE_ID

後續步驟