访问区域性 API 端点

本页面介绍了如何在Google Cloud中使用区域 API 端点(区域端点),这些端点适用于 me-central2(沙特阿拉伯)区域。

区域端点通过在与客户端相同的Google Cloud 区域中路由和处理流量,提供传输中的数据驻留功能。当客户端使用区域端点调用服务时,客户端的 TLS 会话会在端点名称中指示的区域中终止。因此,区域端点应仅用于在单个区域或管辖区内没有依赖关系的工作负载。

您可以通过互联网连接到公共区域端点。对于互联网入站流量,这些端点使用尽力而为的路由,以使传输中的流量保持在区域(或管辖区)内,因为它们不使用全球 Google Front End (GFE)。而是解析为仅在最靠近所选区域的对等互连点上公布的 IP 地址。

例如,在沙特阿拉伯王国 (KSA) 工作的数据工程师可以使用区域服务端点 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 沙特阿拉伯王国 (KSA) 达曼

以下服务支持区域端点:

服务名称 区域端点
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
Dataproc dataproc.me-central2.rep.googleapis.com
Pub/Sub pubsub.me-central2.rep.googleapis.com

配置客户端以从公共互联网访问区域端点

如需通过公共互联网使用区域端点,您必须先配置客户端(例如 Google Cloud CLIGoogle 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 软件包中 ImageAnnotatorSettingsnewBuilder 方法:

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 端点的请求。如需了解详情,请参阅限制端点用量