快速入門導覽課程:啟用 Cloud Location Finder 並執行查詢
本頁面說明如何使用 Google Cloud CLI 啟用 Cloud Location Finder,以及如何依據鄰近程度、管轄區和碳足跡尋找雲端位置。您可以透過 HTTP 要求或 Google Cloud CLI 指令尋找位置。
事前準備
- 安裝 Google Cloud CLI。
- 執行下列指令,初始化 Google Cloud CLI:
gcloud init
- 啟用 Cloud Location Finder API:
gcloud services enable cloudlocationfinder.googleapis.com --project PROJECT
- 新增
cloudlocationfinder.viewer角色:gcloud projects add-iam-policy-binding PROJECT \ --member USER_IDENTIFIER \ --role roles/cloudlocationfinder.viewer- 將 PROJECT 替換為專案 ID。
- 將 USER_IDENTIFIER 替換為使用者帳戶的 ID,例如 user:myemail@example.com。
- 如果您打算使用 Cloud Location Finder 尋找 Google Distributed Cloud 連結網路方案位置,請啟用 GDC Hardware Management API,並新增
gdchardwaremanagement.reader角色:gcloud projects add-iam-policy-binding PROJECT \ --member USER_IDENTIFIER \ --role roles/gdchardwaremanagement.reader
瞭解常見的 Cloud Location Finder 查詢
您可以透過 Cloud Location Finder 查詢雲端位置存放區,根據鄰近程度、地域代碼或 Google 無碳能源 (CFE%) 消耗量,找出附近的雲端位置。以下各節提供與 Cloud Location Finder 存放區互動的常見範例。
Cloud Location Finder 使用 gRPC 轉碼語法。
- 將 PROJECT 替換為專案 ID。
- 將 CLOUD_REGION 替換為來源雲端區域,找出最接近的位置,包括雲端服務供應商前置字元。例如:
gcp-us-central1或aws-us-east-1。 - 將 CLOUD_PROVIDER 替換為雲端供應商,找出最接近的位置。例如:
AWS或GCP。
尋找最近的雲端區域
使用這項查詢,根據您指定的雲端服務供應商的鄰近資料,找出最接近雲端位置的 Google Cloud 區域。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "X-Goog-User-Project: PROJECT" \
-G "https://cloudlocationfinder.googleapis.com/v1/projects/PROJECT/locations/global/cloudLocations:search" \
--data-urlencode "source_cloud_location=projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION" \
--data-urlencode "query=cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_ZONE" \
--data-urlencode "page_size=1"
gcloud
gcloud cloudlocationfinder cloud-locations search \
--source-cloud-location=CLOUD_REGION \
--query="cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_ZONE" \
--limit=1
找出區域中的所有 Google Distributed Cloud 連結網路方案可用區
使用這項查詢,列出特定區域內的 Distributed Cloud connected 可用區。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "X-Goog-User-Project: PROJECT" \
-G "https://cloudlocationfinder.googleapis.com/v1/projects/PROJECT/locations/global/cloudLocations" \
--data-urlencode 'filter=containing_cloud_location="projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION" AND cloud_provider=CLOUD_PROVIDER_GCP AND cloud_location_type=CLOUD_LOCATION_TYPE_GDCC_ZONE'
gcloud
gcloud cloudlocationfinder cloud-locations list \
--filter='cloud_provider=CLOUD_PROVIDER_GCP AND cloud_location_type=CLOUD_LOCATION_TYPE_GDCC_ZONE AND containing_cloud_location="projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION"'
找出特定地域內的區域
使用這項查詢,透過您提供的地域代碼,找出特定地域或管轄區內的區域。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "X-Goog-User-Project: PROJECT" \
-G "https://cloudlocationfinder.googleapis.com/v1/projects/PROJECT/locations/global/cloudLocations:search" \
--data-urlencode "source_cloud_location=projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION" \
--data-urlencode 'query=cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_REGION AND territory_code="TERRITORY_CODE"' \
--data-urlencode "page_size=1"
gcloud
gcloud cloudlocationfinder cloud-locations search \
--source-cloud-location=CLOUD_REGION \
--query="cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_REGION AND territory_code=\"TERRITORY_CODE\"" \
--limit=1
列出可盡量減少碳足跡的雲端位置
根據區域無碳能源 Google Cloud ,使用這項查詢找出碳足跡最低的區域。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "X-Goog-User-Project: PROJECT" \
-G "https://cloudlocationfinder.googleapis.com/v1/projects/PROJECT/locations/global/cloudLocations" \
--data-urlencode "filter=cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_REGION" \
--data-urlencode "page_size=5"
gcloud
gcloud cloudlocationfinder cloud-locations list \
--filter="cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_REGION" \
--limit=5