建立跨雲端連線

跨雲端連線是 BigQuery 連線,可將 Amazon Web Services (AWS)、Microsoft Azure 和 Salesforce Data 360 的資料匯入 BigQuery 進行查詢。這些連結是標準 BigQuery 連結的替代方案,使用 BigQuery Omni,BigQuery 會將輕量運算 worker 部署至遠端區域,讓其他雲端中的資料可供查詢,不需移動任何資料。

相較於標準連線,工作負載可透過跨雲端連線獲得以下好處:

  • 功能一致性。將其他雲端的資料匯入 BigQuery 後,您就能直接使用 BigQuery AI 功能、Gemini Enterprise Agent Platform、materialized view、user-defined function,以及其他無法透過標準連線使用的功能。
  • 成本效益:使用跨雲端連線的工作負載會耗用標準預留運算單元和承諾使用合約,因此不必另外管理運算容量。
  • 智慧型快取。在連線上啟用跨雲端快取功能後,BigQuery 會將擷取的檔案區塊,快取至連線 Google Cloud 區域內的本機。後續針對相同檔案區塊的查詢,會直接從本機快取讀取,而非從遠端雲端重新擷取檔案,有助於降低跨雲端輸出費用,並提升查詢效能。跨雲端快取功能預設為停用。詳情請參閱「智慧型快取」。

如果工作負載涉及 Apache Iceberg 目錄,或需要 BigQuery 以外引擎的查詢支援,建議改用無邊界 Lakehouse 的跨雲端資料存取功能。

事前準備

授予 Identity and Access Management 和第三方角色,讓使用者具備必要權限,可執行本文件中的各項工作。

必要的 BigQuery 角色

如要取得建立跨雲端連線所需的權限,請要求管理員授予您專案的 BigQuery 管理員 (roles/bigquery.admin) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

必要的第三方角色

如要取得建立跨雲端連線所需的權限,請確認您具備下列第三方角色:

  • AWS:可讓您在 AWS 帳戶中建立 IAM 政策和角色的角色。
  • Azure:可讓您在 Microsoft Entra ID (Azure AD) 中管理應用程式註冊,並在目標 Azure 帳戶上指派角色 (例如儲存體 Blob 資料讀取者) 的角色。

建立 AWS 跨雲端連線

如要建立 AWS 跨雲端連線,請按照下列步驟操作:

  1. 按照標準 BigQuery 連線的方式,為 BigQuery 建立 AWS IAM 政策。
  2. 按照標準 BigQuery 連線的方式,為 BigQuery 建立 AWS IAM 角色。
  3. 使用 Google Cloud 控制台或 bq 指令列工具,建立連線資源並擷取其服務帳戶身分:

    控制台

    1. 前往「BigQuery」頁面。

      前往「BigQuery」

    2. 在「Explorer」窗格中展開專案名稱,然後點選「Connections」(連線)。

    3. 在「Connections」(連線) 頁面,按一下「Create connection」(建立連線)。

    4. 在「外部資料來源」窗格,輸入下列資訊:

      • 「連線類型」請選取「BigLake on AWS (via BigQuery Omni)」。
      • 在「連線 ID」部分,輸入連線資源的 ID。
      • 在「Region」(區域) 部分,選取標準 BigQuery 位置 (例如 us-east4),而非 BigQuery Omni 位置。如需選取區域的指引,請參閱「區域建議」。
      • 在「AWS 角色 ID」部分,輸入完整的 IAM 角色 ARN:arn:aws:iam::AWS_ACCOUNT_ID:role/ROLE_NAME。
      • 選用:在「Cross-cloud caching」(跨雲端快取) 下方,選取「Enable cross-cloud caching」(啟用跨雲端快取),將遠端檔案快取至連線的Google Cloud 區域,並加快查詢效能。您也可以稍後在連線的「Connection info」(連線資訊) 頁面中,按一下「Edit details」(編輯詳細資料) 來更新這項設定。如要進一步瞭解快取運作方式、保留和定價,請參閱「智慧型快取」。
    5. 依序點選「建立連線」和「前往連線」。

    6. 在「Connection info」(連線資訊) 窗格中,複製「BigQuery Google identity」(BigQuery Google 身分) 值。

    bq

    1. 如要建立連線資源,請使用 bq mk --connection 指令:

      bq mk --connection \
         --connection_type='AWS' \
         --location=LOCATION \
         --project_id=PROJECT_ID \
         --properties='{"accessRole":{"iamRoleId":"arn:aws:iam::AWS_ACCOUNT_ID:role/ROLE_NAME"},"crossCloudCacheOptions":{"enabled":CROSS_CLOUD_CACHE_ENABLED}}' \
         CONNECTION_ID

      更改下列內容:

      • LOCATION:標準 BigQuery 位置,而非 BigQuery Omni 位置。如需選取區域的指引,請參閱「區域建議」。
      • PROJECT_ID:Google Cloud 專案的 ID。
      • AWS_ACCOUNT_ID:上一步驟中的 AWS IAM 使用者 ID。
      • ROLE_NAME:您選擇的 AWS 角色政策名稱。
      • CROSS_CLOUD_CACHE_ENABLED:選用:是否要啟用連線的跨雲端快取功能 (true 或 false)。預設值為 false。如果設為 true,BigQuery 會將遠端檔案快取至連線的Google Cloud 區域。詳情請參閱「智慧型快取」。
      • CONNECTION_ID:要指派給這個 連線資源的 ID。

      如要進一步瞭解 AWS 連線屬性,請參閱 AwsProperties。

    2. 如要記下服務帳戶資訊,請使用 bq show 指令:

      bq show --connection \
         --location=LOCATION \
         PROJECT_ID.LOCATION.CONNECTION_ID
  4. 使用服務帳戶資訊,為 AWS 角色新增信任政策,就像標準 BigQuery 連線一樣。

建立 AWS 跨雲端連線後,即可建立資料表和資料集,查詢遠端資料。

AWS 範例

以下範例會建立外部資料表,透過跨雲端連線直接從 Amazon Simple Storage Service (Amazon S3) bucket 查詢 Parquet 檔案:

CREATE SCHEMA `my-project.aws_raw_data`
  OPTIONS (
    location = 'us-east4');

CREATE EXTERNAL TABLE `my-project.aws_raw_data.sales_parquet`
WITH CONNECTION `us-east4.my-aws-connection`
  OPTIONS (
    format = 'PARQUET',
    uris = ['s3://my-data-bucket/sales/year=2025/*']);

下列範例使用 AWS Glue 搭配跨雲端連線,將整個資料庫聯合至 BigQuery:

CREATE EXTERNAL SCHEMA `my-project.aws_glue_data`
WITH CONNECTION `us-east4.my-aws-connection`
  OPTIONS (
    location = 'us-east4',
    external_source = 'aws-glue://arn:aws:glue:us-east-4:123456789:database/test_database');

如要進一步瞭解 AWS Glue 聯盟,請參閱「建立及管理 AWS Glue 聯合資料集」。

建立 Azure 跨雲端連線

如要建立 Azure 跨雲端連線,請按照下列步驟操作:

  1. 在 Azure 租戶中建立應用程式,就像建立標準 BigQuery 連線一樣,並記下應用程式 (用戶端) 和目錄 (租戶) ID。
  2. 將角色指派給 Azure 應用程式,就像指派給標準 BigQuery 連線一樣。
  3. 使用 Google Cloud 控制台或 bq 指令列工具,建立連線資源並擷取其服務帳戶身分:

    控制台

    1. 前往「BigQuery」頁面。

      前往「BigQuery」

    2. 在「Explorer」窗格中展開專案名稱,然後點選「Connections」(連線)。

    3. 在「Connections」(連線) 頁面,按一下「Create connection」(建立連線)。

    4. 在「外部資料來源」窗格,輸入下列資訊:

      • 「連線類型」請選取「BigLake on Azure (via BigQuery Omni)」。
      • 在「連線 ID」部分,輸入連線資源的 ID。
      • 在「Region」(區域) 部分,選取標準 BigQuery 位置 (例如 us-east4),而非 BigQuery Omni 位置。如需選取區域的指引,請參閱「區域建議」。
      • 在「Azure tenant ID」(Azure 租戶 ID),輸入 Azure 目錄 (租戶) ID。
      • 選取「Use federated identity」(使用聯合身分),然後在「Azure federated application (client) ID」(Azure 聯合應用程式 (用戶端) ID) 欄位中,輸入 Azure 應用程式 (用戶端) ID。
      • 選用:在「Cross-cloud caching」(跨雲端快取) 下方,選取「Enable cross-cloud caching」(啟用跨雲端快取),將遠端檔案快取至連線的Google Cloud 區域,並加快查詢效能。您也可以稍後在連線的「Connection info」(連線資訊) 頁面中,按一下「Edit details」(編輯詳細資料) 來更新這項設定。如要進一步瞭解快取運作方式、保留和定價,請參閱「智慧型快取」。
    5. 依序點選「建立連線」和「前往連線」。

    6. 在「Connection info」(連線資訊) 窗格中,複製「BigQuery Google identity」(BigQuery Google 身分) 值。

    bq

    1. 如要建立連線資源,請使用 bq mk --connection 指令:

      bq mk --connection \
         --connection_type='Azure' \
         --tenant_id=TENANT_ID \
         --location=LOCATION \
         --federated_azure=true \
         --federated_app_client_id=APP_ID \
         --project_id=PROJECT_ID \
         --properties='{"crossCloudCacheOptions":{"enabled":CROSS_CLOUD_CACHE_ENABLED}}' \
         CONNECTION_ID

      更改下列內容:

      • TENANT_ID:Azure 目錄的租戶 ID,其中包含 Azure 帳戶。
      • LOCATION:標準 BigQuery 位置,而非 BigQuery Omni 位置。如需選取區域的指引,請參閱「區域建議」。
      • APP_ID:Azure 應用程式 (用戶端) ID。
      • PROJECT_ID:Google Cloud 專案的 ID。
      • CROSS_CLOUD_CACHE_ENABLED:選用:是否要啟用連線的跨雲端快取功能 (true 或 false)。預設值為 false。如果設為 true,BigQuery 會將遠端檔案快取至連線的Google Cloud 區域。詳情請參閱「智慧型快取」。
      • CONNECTION_ID:要指派給這項 連線資源的 ID。

      如要進一步瞭解 Azure 連線屬性,請參閱 AzureProperties。

    2. 如要記下服務帳戶資訊,請使用 bq show 指令:

      bq show --connection \
         --location=LOCATION \
         PROJECT_ID.LOCATION.CONNECTION_ID
  4. 使用服務帳戶資訊新增聯合憑證,就像標準 BigQuery 連線一樣。

建立 Azure 跨雲端連線後,您現在可以建立資料表和資料集,查詢遠端資料。

Azure 範例

下列範例會建立外部資料表,透過跨雲端連線直接從 Azure Blob 儲存體容器查詢 Parquet 檔案:

CREATE SCHEMA `my-project.azure_raw_data`
  OPTIONS (
    location = 'us-east4');

CREATE EXTERNAL TABLE `my-project.azure_raw_data.sales_parquet`
WITH CONNECTION `us-east4.my-azure-connection`
  OPTIONS (
    format = 'PARQUET',
    uris = ['azure://mystorageaccount.blob.core.windows.net/mycontainer/sales/year=2025/*']);

下列範例會建立外部資料表,透過跨雲端連線查詢 Blob 儲存體容器中的原始 CSV 匯出內容:

CREATE EXTERNAL TABLE `my-project.azure_raw_data.daily_logs_csv`
WITH CONNECTION `us-east4.my-azure-connection`
  OPTIONS (
    format = 'CSV',
    skip_leading_rows = 1,
    uris = ['azure://mystorageaccount.blob.core.windows.net/mycontainer/logs/*.csv']);

建立 Data 360 跨雲端連線

如要建立 Data 360 跨雲端連結,請按照將 Data 360 資料集連結至 BigQuery 的步驟操作,但請在標準 BigQuery 位置建立連結資料集,而非在 BigQuery Omni 位置建立。如需選取區域的指南,請參閱「區域建議」。

更新查詢以使用新資料集後,即可刪除任何舊版連結資料集和 BigQuery Omni materialized view。

區域建議

為跨雲端連線選取標準 BigQuery 區域時,請選擇與資料實際位置最接近的區域,以達到最佳成本和效能效益。

下表列出 AWS 區域和最適合的對應 BigQuery 區域:

AWS 區域 最接近的 BigQuery 區域 其他鄰近的 BigQuery 區域
us-east-1 us-east4 us-east1
us-east5
us-central1
us-east-2 us-east5 us-east4
us-east1
us-central1
us-west-1 us-west2 us-west4
us-west1
us-west3
us-west-2 us-west1 us-west3
us-west4
us-west2
ca-central-1 northamerica-northeast1 northamerica-northeast2
us-east4
us-east5
sa-east-1 southamerica-east1 southamerica-west1
us-east1
us-south1
eu-west-1 europe-west1 europe-west2
europe-west9
europe-west4
eu-west-2 europe-west2 europe-west1
europe-west9
europe-west4
eu-west-3 europe-west9 europe-west1
europe-west2
europe-west3
eu-central-1 europe-west3 europe-west4
europe-west1
europe-west6
eu-central-2 europe-west6 europe-west8
europe-west12
europe-west3
eu-north-1 europe-north1 europe-west4
europe-central2
europe-west1
eu-south-1 europe-west8 europe-west12
europe-west6
europe-west3
eu-south-2 europe-southwest1 europe-west9
europe-west1
europe-west8
me-central-1 me-central1 me-central2
me-west1
asia-south1
me-south-1 me-central2 me-central1
me-west1
asia-south1
af-south-1 europe-southwest1 me-central2
me-west1
europe-west1
ap-east-1 asia-east2 asia-east1
asia-southeast1
asia-northeast1
ap-northeast-1 asia-northeast1 asia-northeast2
asia-northeast3
asia-east1
ap-northeast-2 asia-northeast3 asia-northeast2
asia-northeast1
asia-east1
ap-northeast-3 asia-northeast2 asia-northeast1
asia-northeast3
asia-east1
ap-south-1 asia-south1 asia-south2
me-central1
asia-southeast1
ap-south-2 asia-south2 asia-south1
asia-southeast1
me-central1
ap-southeast-1 asia-southeast1 asia-southeast2
asia-east1
asia-south1
ap-southeast-2 australia-southeast1 australia-southeast2
asia-southeast2
asia-southeast1
ap-southeast-3 asia-southeast2 asia-southeast1
australia-southeast1
asia-east1

下表列出 Azure 區域和最適合的對應 BigQuery 區域:

Azure 區域 最接近的 BigQuery 區域 其他鄰近的 BigQuery 區域
美國東部 us-east4 us-east1
us-east5
us-central1
美國東部 2 us-east4 us-east1
us-east5
us-south1
美國西部 us-west1 us-west2
us-west3
us-west4
West US 2 us-west1 us-west4
us-west3
us-west2
美國西部 3 us-west4 us-west2
us-west3
us-west1
美國中部 us-central1 us-east5
us-east4
us-east1
美國中北部 us-east5 us-central1
us-east4
us-east1
美國中南部 us-south1 us-east5
us-central1
us-east1
美國中西部 us-west3 us-central1
us-west4
us-west2
加拿大中部 northamerica-northeast2 northamerica-northeast1
us-east5
us-east4
加拿大東部 northamerica-northeast1 northamerica-northeast2
us-east4
us-east5
西歐 europe-west4 europe-west1
europe-west3
europe-west9
北歐 europe-west1 europe-west2
europe-west9
europe-west4
法國中部 europe-west9 europe-west1
europe-west2
europe-west3
法國南部 europe-west9 europe-southwest1
europe-west8
europe-west1
德國中西部 europe-west3 europe-west4
europe-west1
europe-west6
德國北部 europe-west3 europe-west4
europe-central2
europe-west2
瑞士北部 europe-west6 europe-west8
europe-west12
europe-west3
瑞士西部 europe-west6 europe-west9
europe-west8
europe-west3
英國南部 europe-west2 europe-west1
europe-west9
europe-west4
英國西部 europe-west2 europe-west1
europe-west9
europe-west4
挪威東部 europe-north1 europe-west4
europe-central2
europe-west1
挪威西部 europe-north1 europe-west4
europe-central2
europe-west1
瑞典中部 europe-north1 europe-west4
europe-central2
europe-west1
東亞 asia-east2 asia-east1
asia-southeast1
asia-northeast1
東南亞 asia-southeast1 asia-southeast2
asia-east1
asia-south1
日本東部 asia-northeast1 asia-northeast2
asia-northeast3
asia-east1
日本西部 asia-northeast2 asia-northeast1
asia-northeast3
asia-east1
韓國中部 asia-northeast3 asia-northeast2
asia-northeast1
asia-east1
澳洲東部 australia-southeast1 australia-southeast2
asia-southeast2
asia-southeast1
澳洲東南部 australia-southeast2 australia-southeast1
asia-southeast1
asia-east1
澳洲中部 australia-southeast1 australia-southeast2
asia-southeast2
asia-southeast1
西印度 asia-south1 asia-south2
me-central1
asia-southeast1
印度中部 asia-south1 asia-south2
me-central1
asia-southeast1
印度南部 asia-south1 asia-south2
asia-southeast1
me-central1

排解跨雲端連線問題

本節說明如何解決使用跨雲端連線時的常見問題。

AWS 連線未獲授權,無法擔任 IAM 角色

您可能會看到類似下方的錯誤訊息:

Connection CONNECTION_NAME isn't authorized to assume into your AWS IAM Role.

請按照下列步驟解決這個問題:

  • 確認連線的 iamRoleId 是 AWS IAM 角色的 ARN。如要查看連線屬性,請使用 bq show 指令。
  • 確認角色的信任政策包含 bq show 輸出內容中的連線 identity 值。詳情請參閱「為 AWS 角色新增信任政策」。
  • 如果您剛建立連線或變更信任政策,請稍候幾分鐘,讓變更在 AWS 中生效,然後再試一次。

AWS IAM 角色工作階段持續時間過短

您可能會看到類似下方的錯誤訊息:

Connection CONNECTION_NAME failed assuming into your AWS IAM role because the session
duration of your IAM Role is smaller than the requested session duration.

如要解決這個問題,請將 AWS IAM 角色的工作階段持續時間上限設為 12 小時 (43200 秒)。

AWS 帳戶有 Google 專用的自訂識別資訊提供者

您可能會看到類似下方的錯誤訊息:

Connection: CONNECTION_NAME cannot assume AWS IAM Role. This can result when your AWS
account has a custom identity provider for Google.

如要解決這個問題,請將連線的 identity 值新增至自訂識別資訊提供者的目標對象。詳情請參閱「設定自訂 AWS 識別資訊提供者」。

從 Amazon S3 讀取資料時,存取權遭拒

您可能會看到類似下方的錯誤訊息:

BigQuery received AccessDenied from S3 for 'OPERATION' on bucket 'BUCKET' path 'PATH'
in region 'REGION' using Connection 'CONNECTION'. This could be due to insufficient
permission, or the path doesn't exist.

請按照下列步驟解決這個問題:

  • 確認資料表的 uris 選項中,bucket 和路徑確實存在。
  • 確認附加至角色的 IAM 政策,會授予 bucket 的 s3:ListBucket 權限和物件的 s3:GetObject 權限。詳情請參閱「為 BigQuery 建立 AWS IAM 政策」。
  • 如果物件是以 AWS KMS 金鑰加密,請確認該角色具備金鑰的 kms:Decrypt 權限。

Azure 應用程式拒絕連線

您可能會看到類似下方的錯誤訊息:

BigQuery received an error from Azure when attempting to use connection CONNECTION_NAME
to access your Azure application.

請按照下列步驟解決這個問題:

  • 確認連線的 customerTenantId 和 federatedApplicationClientId 與 Azure 應用程式的目錄 (租戶) ID 和應用程式 (用戶端) ID 相符。如要查看連線屬性,請使用 bq show 指令。
  • 確認應用程式的聯合憑證使用 bq show 輸出內容中的連線 identity 值。詳情請參閱「新增聯合憑證」。
  • 如果您剛建立連線或聯合憑證,請稍候幾分鐘,待變更在 Azure 中生效後再試一次。

讀取 Blob 儲存體時,存取權遭拒

您可能會看到類似下方的錯誤訊息:

BigQuery received AccessDenied from Azure Blob Storage for 'OPERATION' on storage account
'STORAGE_ACCOUNT' container 'CONTAINER' path 'PATH' using Connection 'CONNECTION'.
This could be due to insufficient permission granted to BigQuery.

如要解決這個問題,請確認 Azure 應用程式在儲存體帳戶或容器中具備角色,例如儲存體 Blob 資料讀取者。詳情請參閱「為 Azure 應用程式指派角色」。

找不到 bucket、容器或路徑

您可能會看到開頭為 BigQuery received NotFound from S3 或 BigQuery received NotFound from Azure Blob Storage 的錯誤訊息。如要解決這個問題,請確認資料表 uris 選項中的 bucket、儲存體帳戶、容器和路徑確實存在,且拼寫正確。

後續步驟