Cloud Scheduler 區域端點可讓您將 API 流量保留在單一Google Cloud 區域內,協助符合資料落地和資料主權規定。當您向區域端點傳送要求時,TLS 會終止,Cloud Scheduler 則會在指定區域內完整處理要求。
Cloud Scheduler 區域端點的格式為 https://cloudscheduler.REGION.rep.googleapis.com,其中 REGION 是支援的區域,例如 https://cloudscheduler.us-central1.rep.googleapis.com。
如要瞭解如何使用 Private Service Connect,從虛擬私有雲 (VPC) 網路內部私下存取 Cloud Scheduler 區域端點,請參閱「關於透過端點存取區域和多區域 Google API」。
限制和規定
使用 Cloud Scheduler 區域端點時,須遵守下列限制。
- 區域端點只會提供所在區域的資源。資源名稱中的位置必須與端點的區域相符。例如,您可以將
projects/PROJECT_ID/locations/us-central1中的資源要求傳送至cloudscheduler.us-central1.rep.googleapis.com。其他區域的資源要求則會失敗。 - 區域端點適用於傳送至 Cloud Scheduler API 的要求。不會影響 Cloud Scheduler 將要求傳送至工作目標的方式。如果工作是在 VPC Service Controls 範圍內執行,請參閱「使用 VPC Service Controls 保護 Cron 工作」一文,瞭解工作目標的需求條件。
將要求傳送至區域端點
您可以使用 Google Cloud CLI、REST API 或 Cloud Scheduler 用戶端程式庫,將要求傳送至區域端點。
gcloud
將 api_endpoint_overrides/cloudscheduler 屬性設為區域端點,然後針對該區域中的資源執行 gcloud scheduler 指令:
gcloud config set api_endpoint_overrides/cloudscheduler \ https://cloudscheduler.REGION.rep.googleapis.com/ gcloud scheduler jobs list --location=REGION
將 REGION 替換為提供區域端點的區域,例如 us-central1。
如要再次使用預設全域端點,請取消設定屬性:
gcloud config unset api_endpoint_overrides/cloudscheduler
REST
使用區域端點做為要求網址的主機。舉例來說,下列指令會列出某個區域中的工作:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://cloudscheduler.REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/jobs"
更改下列內容:
REGION:提供區域端點的區域,例如us-central1。PROJECT_ID:您的 Google Cloud 專案 ID。
用戶端程式庫
建立用戶端時,請設定 API 端點。以下範例會為 us-central1 建立用戶端:
Go
import ( scheduler "cloud.google.com/go/scheduler/apiv1" "google.golang.org/api/option" ) client, err := scheduler.NewCloudSchedulerClient(ctx, option.WithEndpoint("cloudscheduler.us-central1.rep.googleapis.com:443"))
Java
import com.google.cloud.scheduler.v1.CloudSchedulerClient; import com.google.cloud.scheduler.v1.CloudSchedulerSettings; CloudSchedulerSettings settings = CloudSchedulerSettings.newBuilder() .setEndpoint("cloudscheduler.us-central1.rep.googleapis.com:443") .build(); try (CloudSchedulerClient client = CloudSchedulerClient.create(settings)) { // Send requests for resources in us-central1. }
Python
from google.api_core.client_options import ClientOptions from google.cloud import scheduler_v1 client = scheduler_v1.CloudSchedulerClient( client_options=ClientOptions( api_endpoint="cloudscheduler.us-central1.rep.googleapis.com" ) )