存取區域 API 端點

本頁面說明如何在Google Cloud中使用區域 API 端點 (區域端點),這些端點適用於me-central2 (KSA) 區域。

區域端點會將流量轉送至與用戶端相同的Google Cloud 區域,並在該區域提供服務,藉此提供傳輸中資料落地功能。用戶端使用區域端點呼叫服務時,用戶端的 TLS 工作階段會在端點名稱指定的區域終止。因此,區域端點只能用於在單一區域或管轄區以外沒有依附元件的工作負載。

您可以透過網際網路連線至公開區域端點。對於網際網路輸入流量,這些端點會使用盡力而為轉送,將傳輸中的流量保留在區域 (或管轄區) 內,因為這些端點不使用全域 Google Front End (GFE)。而是解析為僅在最靠近所選區域的對接點上宣告的 IP 位址。

舉例來說,在沙烏地阿拉伯工作的資料工程師,可以使用區域服務端點 bigquery.me-central2.rep.googleapis.com,將用戶端設為使用 me-central2 區域 (達曼) 的 BigQuery。流量會使用標準級轉送,且用戶端的 TLS 工作階段會在 me-central2 終止。

在這種情況下,對應至區域性服務端點的公開 VIP,會源自 Google 在區域對接點上宣告的 IP 前置字串。因此,如果使用者連線至沙烏地阿拉伯的當地 ISP,流量可以在其管轄範圍內轉送。

區域端點格式

區域端點的格式如下:

SERVICE_NAME.REGION.rep.googleapis.com

預留位置值的定義如下:

  • SERVICE_NAME:支援的服務端點名稱,例如 bigquery。
  • REGION:支援的 Google Cloud 區域,例如 me-central2。

以下是 BigQuery 完整區域端點的範例:

bigquery.me-central2.rep.googleapis.com

支援的地區和服務

下列區域支援區域端點:

區域名稱 位置
me-central2 沙烏地阿拉伯王國達曼

下列服務支援區域端點:

服務名稱 區域端點
App Hub apphub.me-central2.rep.googleapis.com
Artifact Registry artifactregistry.me-central2.rep.googleapis.com
apt.me-central2.rep.pkg.dev
docker.me-central2.rep.pkg.dev
go.me-central2.rep.pkg.dev
googet.me-central2.rep.pkg.dev
kfp.me-central2.rep.pkg.dev
maven.me-central2.rep.pkg.dev
npm.me-central2.rep.pkg.dev
python.me-central2.rep.pkg.dev
yum.me-central2.rep.pkg.dev
BigQuery bigquery.me-central2.rep.googleapis.com
bigquerydatatransfer.me-central2.rep.googleapis.com
bigquerymigration.me-central2.rep.googleapis.com
bigqueryreservation.me-central2.rep.googleapis.com
bigquerystorage.me-central2.rep.googleapis.com
Bigtable bigtable.me-central2.rep.googleapis.com
Cloud Key Management Service (Cloud KMS) cloudkms.me-central2.rep.googleapis.com
Cloud Logging logging.me-central2.rep.googleapis.com
Spanner spanner.me-central2.rep.googleapis.com
Cloud Storage storage.me-central2.rep.googleapis.com
Dataflow dataflow.me-central2.rep.googleapis.com
Managed Service for Apache Spark dataproc.me-central2.rep.googleapis.com
Pub/Sub pubsub.me-central2.rep.googleapis.com

設定用戶端,以便從公開網際網路存取區域端點

如要透過公開網際網路使用區域端點,您必須先設定用戶端 (例如 Google Cloud CLI 或 Google Cloud SDK 用戶端程式庫),連線至特定區域端點。

設定 gcloud CLI

根據預設,gcloud CLI 會使用全域服務端點,例如 bigquery.googleapis.com。如要使用區域性服務端點,您必須完成下列步驟,設定 gcloud CLI 來使用這些端點。

  1. 如果尚未啟用支援的服務,請使用下列指令啟用:

    gcloud services enable SERVICE_NAME

    將 SERVICE_NAME 替換為要使用的支援服務名稱。例如:

    gcloud services enable cloudkms
  2. 如要使用區域性服務端點,您必須使用 gcloud config set api_endpoint_overrides 指令設定 gcloud CLI:

    gcloud config set api_endpoint_overrides/SERVICE_NAME REGIONAL_API_URL

    將下列值替換為您自己的值:

    • SERVICE_NAME:要使用的支援服務名稱。例如:cloudkms
    • REGIONAL_API_URL:特定端點的網址。例如:

      https://SERVICE_NAME.REGION_NAME.rep.googleapis.com/SERVICE_NAME/API_VERSION

      將下列值替換為您自己的值:

      • REGION_NAME:必要 Google Cloud 區域的名稱。例如:me-central2
      • API_VERSION:要使用的服務 API 版本。例如:v1。注意:部分服務可能不需要這項參數。

      以下是 REGIONAL_API_URL 值範例:

      https://cloudkms.me-central2.rep.googleapis.com/cloudkms/v1

    以下是 Cloud KMS 的 gcloud config set api_endpoint_overrides 指令範例:

    gcloud config set api_endpoint_overrides/cloudkms https://cloudkms.me-central2.rep.googleapis.com/cloudkms/v1

現在 gcloud CLI 已設為使用區域性服務端點,日後指令會預設使用該端點,而非全域服務端點。

設定 Google Cloud SDK 用戶端程式庫

根據預設,Google Cloud SDK 用戶端程式庫會使用全域服務端點,例如 pubsub.googleapis.com。如要使用區域性服務端點,您必須設定 Google Cloud SDK 用戶端程式庫,才能使用這些端點。

Python

在 google-api-core 套件的 ClientOptions 類別中設定 api_endpoint 參數:

from google.api_core.client_options import ClientOptions

options = ClientOptions(api_endpoint = "pubsub.me-central2.rep.googleapis.com")
client = pubsub_v1.PublisherClient(client_options=options)

// Alternatively
client = pubsub_v1.PublisherClient(client_options={"api_endpoint": "pubsub.me-central2.rep.googleapis.com")

Java

使用 com.google.cloud.vision 套件中 ImageAnnotatorSettings 類別的 newBuilder 方法:

ImageAnnotatorSettings settings = ImageAnnotatorSettings.newBuilder()
  .setEndpoint("pubsub.me-central2.rep.googleapis.com")
  .build();
ImageAnnotatorClient client = ImageAnnotatorClient.create(settings);

Go

使用 api 套件的 ClientOptions 套件中的 WithEndpoint 函式:

client, err := pubsub.NewClient(ctx, projID,
    option.WithEndpoint("pubsub.me-central2.rep.googleapis.com"), // Override endpoint

.NET

在所用程式庫的 Google.Cloud 套件中,設定用戶端 ClientBuilder 類別的 Endpoint 屬性:

string region = "me-central2";
var client = new DatasetServiceClientBuilder
{
    Endpoint = $"pubsub.{region}.rep.googleapis.com"
}.Build();

限制全域 API 端點用量

如要強制使用區域端點,請使用 constraints/gcp.restrictEndpointUsage 組織政策限制,封鎖對全域 API 端點的要求。詳情請參閱「限制端點用量」。