View a markdown version of this page

將中繼資料匯出至 S3 Tables (預覽) - AWS Glue

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

將中繼資料匯出至 S3 Tables (預覽)

注意

目錄中繼資料匯出可作為預覽功能。此功能在一般可用性之前可能會有所變更。

概觀

您可以將 AWS Glue Data Catalog 中繼資料匯出至存放在 Amazon S3 資料表中的受管目錄系統資料表。當您啟用 S3 Tables 匯出時,您的技術和業務中繼資料會存放在 AWS 受管資料表儲存貯體中的唯讀 Apache Iceberg aws-catalog資料表中,使其可使用 SQL 搭配 AWS 、Amazon Redshift 和 Amazon EMR 等分析服務來查詢。

在aws-catalog資料表儲存貯體中,系統資料表位於下列命名空間中:

  • glue — 包含 tables和 table_columns。

  • catalog_metadata — 包含 glossaries、glossary_terms、attachments、 associated_glossary_terms和 item_attachments。

目前支援下列系統資料表:

系統資料表 Contains

tables

Data Catalog 中每個資料表的技術與商業中繼資料,例如其名稱、資料庫、描述、儲存位置和格式。

table_columns

每個目錄資料表的資料欄,包括每個資料欄的名稱、資料類型、描述,以及是否為分割區索引鍵。

glossaries

目錄中的業務詞彙表,包括每個詞彙表的名稱、描述和狀態。

glossary_terms

詞彙表中定義的詞彙,包括每個詞彙的名稱、描述、父詞彙表和狀態。

associated_glossary_terms

詞彙表詞彙與資產之間的關聯,包括資產識別符和詞彙表詞彙識別符。

attachments

在資產層級附加的自訂表單中繼資料,包括表單類型和附件內容。

item_attachments

連接到資產中項目的自訂表單中繼資料,例如個別資料欄,包括可重複的表單名稱、項目名稱、表單類型和附件內容。

如需每個資料表的完整資料欄層級結構描述,請參閱 目錄系統資料表參考。

目錄中繼資料匯出的運作方式

啟用匯出後,Data Catalog 會執行現有目錄中繼資料的一次性回填,然後在您進行變更時讓系統資料表保持在最新狀態。新寫入或更新的中繼資料通常會在大約 5 分鐘內顯示在系統資料表中。

系統資料表位於aws-catalog資料表儲存貯體中的 glue和 catalog_metadata 命名空間中。指定的系統資料表會在您的目錄中第一次存在該類型的中繼資料時出現。例如,如果您啟用匯出,且目錄只包含資料表和資料庫,則只會看到與資料表相關的系統資料表。詞彙表系統資料表會在您建立第一個詞彙表後顯示。

使用 啟用目錄中繼資料匯出 AWS CLI

目錄中繼資料匯出是帳戶層級設定。您可以使用 啟用或停用它 AWS CLI。

先決條件

您使用的 IAM 身分必須具有呼叫匯出組態操作 glue:PutDataCatalogExportConfiguration 和 glue:GetDataCatalogExportConfiguration以及 的許可s3tables:CreateTable。如需 S3 Tables 許可的詳細資訊,請參閱《Amazon Simple Storage Service 使用者指南》中的在 S3 資料表儲存貯體中建立資料表。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "glue:PutDataCatalogExportConfiguration", "glue:GetDataCatalogExportConfiguration" ], "Resource": "*" } ] }

S3 Tables 中的所有資料,包括 Data Catalog 中繼資料,預設會使用 SSE-S3 加密進行加密。您可以選擇使用 AWS KMS 金鑰 (SSE-KMS) 加密目錄匯出。如果您選擇使用 AWS KMS 金鑰加密,則必須採取下列步驟來新增其他許可:

  1. 授予 Data Catalog 匯出服務主體和 S3 Tables 維護服務主體許可,以使用您的 KMS 金鑰 (金鑰政策)。

  2. 授予執行匯出許可的 IAM 主體,以使用 KMS 金鑰 (身分政策)。

將 Data Catalog 匯出服務主體和 S3 Tables 維護服務主體許可授予 KMS 金鑰

若要允許 AWS Glue 匯出加密的目錄中繼資料,並在匯出的資料表上允許自動資料表維護,例如壓縮和非參考檔案移除,您必須授予下列服務主體存取 KMS 金鑰的權限:

  • systemtables.catalog.amazonaws.com — 將加密的目錄中繼資料匯出至 S3 Tables。

  • maintenance.s3tables.amazonaws.com — 對匯出的資料表執行自動資料表維護。

AWS Glue 會寫入名為 的 AWS 受管資料表儲存貯體aws-catalog。用於加密 S3 Tables 匯出的 KMS 金鑰不需要與用於加密靜態資料目錄的 KMS 金鑰相同。 僅 AWS Glue 支援對稱 KMS 金鑰。若要授予這些服務主體存取權,您可以使用下列範例金鑰政策。在此政策中,maintenance.s3tables.amazonaws.com授予服務主體使用特定 KMS 金鑰來加密和解密資料表儲存貯體中aws-catalog資料表的許可。如需 S3 Tables 維護服務主體的詳細資訊,請參閱《Amazon Simple Storage Service 使用者指南》中的 S3 Tables SSE-KMS 加密的許可要求。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSystemTablesDescribeKey", "Effect": "Allow", "Principal": { "Service": "systemtables.catalog.amazonaws.com" }, "Action": [ "kms:DescribeKey" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012" } } }, { "Sid": "AllowSystemTablesEncryptDecrypt", "Effect": "Allow", "Principal": { "Service": "systemtables.catalog.amazonaws.com" }, "Action": [ "kms:GenerateDataKey", "kms:Decrypt" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012" }, "StringLike": { "kms:EncryptionContext:aws:s3:arn": "arn:aws:s3tables:us-east-1:123456789012:bucket/aws-catalog/table/*", "kms:ViaService": "s3.us-east-1.amazonaws.com" } } }, { "Sid": "AllowS3TablesMaintenanceEncryptDecrypt", "Effect": "Allow", "Principal": { "Service": "maintenance.s3tables.amazonaws.com" }, "Action": [ "kms:GenerateDataKey", "kms:Decrypt" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012" }, "StringLike": { "kms:EncryptionContext:aws:s3:arn": "arn:aws:s3tables:us-east-1:123456789012:bucket/aws-catalog/*" } } } ] }

匯出主體所需的 IAM 許可

授予執行匯出的主體下列許可。下列政策授予 IAM 主體解密特定 AWS Glue Data Catalog範圍的glue_catalog_id加密內容的存取權 (值是您的 catalogId)。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowDescribeKey", "Effect": "Allow", "Action": [ "kms:DescribeKey" ], "Resource": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012" } } }, { "Sid": "AllowExportOfGlueDataCatalogByCatalogId", "Effect": "Allow", "Action": [ "kms:Decrypt", "kms:GenerateDataKey" ], "Resource": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012", "kms:EncryptionContext:glue_catalog_id": "123456789012" } } } ] }

啟用目錄中繼資料匯出

  1. 執行下列命令以啟用匯出:

    aws glue put-data-catalog-export-configuration \ --export-setting ENABLED
  2. 執行下列命令來確認組態:

    aws glue get-data-catalog-export-configuration

    回應範例:

    { "ExportSetting": "ENABLED", "Status": "ENABLED", "S3TableBucketArn": "arn:aws:s3tables:us-east-1:111122223333:bucket/aws-catalog" }

    ENABLING ENABLED 隨著初始回填進度, Status 欄位會從 轉換為 。

停用目錄中繼資料匯出

執行以下命令:

aws glue put-data-catalog-export-configuration \ --export-setting DISABLED

目錄系統資料表參考

所有系統資料表都位於aws-catalog資料表儲存貯體內的 glue或 catalog_metadata 命名空間中。每個資料表都包含下列系統資料欄:

資料行 Type 說明

ingestion_time

timestamp

記錄擷取到系統資料表 (UTC) 的時間。

schema_version

string

資料表的結構描述版本識別符。

資料表

每個目錄資料表包含一個資料列。

資料行 Type Description

id

string

資料表的唯一識別符。

catalog_id

string

目錄識別符。

catalog_name

string

目錄名稱。

update_time

timestamp

上次更新時間戳記。

created_time

timestamp

建立時間戳記。

created_by_id

string

建立資料表之主體的識別符。

created_by_type

string

建立主體的類型。

description

string

資料表描述。

name

string

資料表名稱

namespace

string

資料表的命名空間。

region_name

string

AWS 區域。

tags

map<string, string>

資源標籤。

type

string

資產類型。

updated_by_id

string

上次更新資料表之主體的識別符。

updated_by_type

string

更新主體的類型。

database_name

string

包含資料表的資料庫。

input_format

string

輸入格式類別。

lake_formation_registration

string

AWS Lake Formation 註冊狀態。

output_format

string

輸出格式類別。

owner

string

資料表擁有者。

retention

int

保留期間。

serde_library

string

序列化/還原序列化程式庫。

table_data_format

string

資料格式。

table_data_location

string

資料位置 URI。

table_format

string

資料表格式 (例如 Iceberg、Hudi)。

table_type

string

資料表類型。

table_columns

包含目錄資料表中每欄一列。

資料行 Type Description

id

string

複合識別符的格式為 assetId#columnName。

asset_id

string

父資料表的識別符。

column_name

string

資料欄名稱。

description

string

資料欄描述。

type

string

資料欄資料類型。

is_partition_key

boolean

資料欄是否為分割區索引鍵。

attachments

包含資產層級自訂表單附件 (資產上的每個附件一列)。

資料行 Type Description

asset_id

string

父資產的識別符。

attachment_name

string

附件名稱。

form_type_id

string

內容的註冊表單類型。

content_json

string

以 JSON 編碼字串的形式連接內容。

item_attachments

在可重複形式的項目上包含附件,例如個別資料欄。

資料行 Type Description

asset_id

string

父資產的識別符。

iterable_form_name

string

可疊代形式的名稱 (例如資料欄)。

item_name

string

項目的名稱 (例如資料欄名稱)。

attachment_name

string

附件名稱。

form_type_id

string

內容的註冊表單類型。

content_json

string

以 JSON 編碼字串的形式連接內容。

詞彙表

每個詞彙表包含一個資料列。

資料行 Type Description

id

string

唯一詞彙表識別符。

description

string

詞彙表描述。

name

string

詞彙表名稱。

status

string

狀態 (ENABLED 或 DISABLED)。

glossary_terms

每個詞彙表字詞包含一個資料列。

資料行 Type Description

id

string

唯一字詞識別符。

glossary_id

string

父詞彙表的識別符。

long_description

string

詳細的術語描述。

name

string

術語名稱。

short_description

string

簡短的術語描述。

status

string

狀態 (ENABLED 或 DISABLED)。

associated_glossary_terms

包含詞彙表詞彙與資產之間的每個關聯一列。

資料行 Type Description

asset_id

string

詞彙表詞彙相關聯的資產識別符。

glossary_term_id

string

與資產相關聯的詞彙表字詞識別符。加入glossary_terms資料表。

查詢目錄系統資料表

您必須先在 AWS 受管資料表儲存貯體上啟用分析整合,並設定 AWS Lake Formation 許可,才能使用 或 Amazon EMR 等 AWS 分析服務查詢匯出至 S3 aws-catalog資料表的目錄中繼資料。

先決條件

  • 目錄中繼資料匯出已啟用,狀態為 ENABLED。

  • 存取 或其他 分析服務。

  • 啟用資料可用的匯出後等待 5 分鐘。

整合概觀

如需將 S3 Tables 與 AWS 分析服務整合的詳細資訊,包括先決條件、IAM 角色組態和step-by-step程序,請參閱《Amazon Simple Storage Service 使用者指南》中的將 Amazon S3 Tables 與 AWS 分析服務整合。

啟用 S3 Tables 匯出並設定分析整合之後,您可以使用 、Amazon Redshift 和 Amazon EMR 等 AWS 分析服務來查詢 Data Catalog 中繼資料。這可讓您使用標準 SQL 執行中繼資料稽核和分析。

查詢範例

列出所有目錄資料表及其資料庫和格式

SELECT id, name, database_name, table_format FROM aws_catalog.glue.tables;
尋找具有特定資料表描述的資料欄

SELECT column_name, type, description FROM aws_catalog.glue.table_columns WHERE asset_id = 'table-id';
將詞彙表詞彙加入其父詞彙表

SELECT g.name AS glossary_name, t.name AS term_name, t.short_description FROM aws_catalog.catalog_metadata.glossary_terms t JOIN aws_catalog.catalog_metadata.glossaries g ON t.glossary_id = g.id WHERE g.status = 'ENABLED';
尋找與特定詞彙表詞彙相關聯的資料表

SELECT t.name, t.database_name, gt.name AS term_name FROM aws_catalog.glue.tables t JOIN aws_catalog.catalog_metadata.associated_glossary_terms agt ON agt.asset_id = t.id JOIN aws_catalog.catalog_metadata.glossary_terms gt ON gt.id = agt.glossary_term_id WHERE gt.name = 'term-name';
從自訂格式附件擷取欄位

SELECT asset_id, attachment_name, json_extract_scalar(content_json, '$.owner') AS data_owner FROM aws_catalog.catalog_metadata.attachments WHERE form_type_id = 'your-form-type-id';