

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

# 與 Amazon S3 資料表整合
<a name="glue-federation-s3tables"></a>

AWS Glue Data Catalog 與 Amazon S3 Tables 整合，可讓您使用單一目錄探索、查詢 S3 Tables，並將 S3 Tables 與 Amazon S3 資料湖中的資料聯結。當您將 S3 Tables 與 Data Catalog 整合時，服務會建立聯合目錄結構，將 S3 Tables 資源映射至 AWS Glue 目錄物件：
+ S3 資料表儲存貯體會成為 Data Catalog 中的目錄
+ S3 命名空間會成為 AWS Glue 資料庫
+ S3 資料表會變成 AWS Glue 資料表

## 存取控制
<a name="s3-tables-access-controls"></a>

Data Catalog 支援兩種 S3 Tables 整合的存取控制模式：
+ **IAM 存取控制** – 使用 IAM 政策來控制對 S3 Tables 和 Data Catalog 的存取。在此方法中，您需要 S3 Tables 資源和 Data Catalog 物件的 IAM 許可，才能存取資源。
+ **AWS Lake Formation 存取控制** – 除了 IAM AWS Glue 許可之外，還使用 AWS Lake Formation 授予來控制透過 Data Catalog 對 S3 Tables 的存取。在此模式中，主體需要 IAM 許可才能與 Data Catalog 互動，並且 AWS Lake Formation 授予 會決定主體可存取的目錄資源 （資料庫、資料表、資料欄、資料列）。此模式同時支援粗粒存取控制 （資料庫層級和資料表層級授予） 和精細存取控制 （資料欄層級和資料列層級安全性）。設定已註冊角色並啟用憑證販賣時，委託人不需要 S3 Tables IAM 許可，因為 會使用已註冊角色代表委託人 AWS Lake Formation 提供憑證。 AWS Lake Formation 存取控制也支援第三方分析引擎的憑證販賣。如需詳細資訊，請參閱《 *AWS Lake Formation 開發人員指南*》中的[建立 S3 資料表目錄](https://docs.aws.amazon.com/lake-formation/latest/dg/create-s3-tables-catalog.html)。

您可以隨著需求發展，在存取控制模式之間遷移。

## 自動掛載的目錄階層
<a name="s3-tables-catalog-hierarchy"></a>

當您使用 Amazon S3 管理主控台將 S3 Tables 與 Data Catalog 整合時，主控台會在您帳戶中的 Data Catalog `s3tablescatalog`中建立名為 的聯合目錄 AWS 。 Amazon S3 此聯合目錄可做為該帳戶和區域中所有現有和未來 S3 資料表儲存貯體的父目錄。整合會映射下列階層中的 Amazon S3 資料表儲存貯體資源：
+ **聯合目錄** – `s3tablescatalog`（自動建立）
+ **子目錄** – 每個 S3 資料表儲存貯體都會在 下成為子目錄 `s3tablescatalog`
+ **資料庫** – 資料表儲存貯體中的每個 S3 命名空間都會成為資料庫
+ **資料表** – 命名空間中的每個 S3 資料表都會成為資料表

例如，如果您有一個名為 "analytics-bucket" 的 S3 資料表儲存貯體，其命名空間為 "sales"，其中包含資料表 "transactions"，則資料目錄中的完整路徑為： `s3tablescatalog/analytics-bucket/sales/transactions`

此四部分階層適用於 S3 Tables 和 Data Catalog 位於相同帳戶中的相同 AWS 帳戶案例。對於跨帳戶案例，您可以在 Data Catalog 中手動掛載個別 S3 資料表儲存貯體，這會建立三部分階層。

## 支援的區域
<a name="s3-tables-supported-regions"></a>

S3 Tables 與 Data Catalog 的整合可在下列 AWS 區域使用：


| 區域代碼 | 區域名稱 | 
| --- | --- | 
| us-east-1 | 美國東部 (維吉尼亞北部) | 
| us-east-2 | 美國東部 (俄亥俄) | 
| us-west-1 | 美國西部 (加利佛尼亞北部) | 
| us-west-2 | 美國西部 (奧勒岡) | 
| af-south-1 | 非洲 (開普敦) | 
| ap-east-1 | 亞太地區 (香港) | 
| ap-east-2 | 亞太區域 (台北) | 
| ap-northeast-1 | 亞太地區 (東京) | 
| ap-northeast-2 | 亞太地區 (首爾) | 
| ap-northeast-3 | 亞太地區 (大阪) | 
| ap-south-1 | 亞太地區 (孟買) | 
| ap-south-2 | 亞太地區 (海德拉巴) | 
| ap-southeast-1 | 亞太地區 (新加坡) | 
| ap-southeast-2 | 亞太地區 (悉尼) | 
| ap-southeast-3 | 亞太地區 (雅加達) | 
| ap-southeast-4 | 亞太地區 (墨爾本) | 
| ap-southeast-5 | 亞太地區 (馬來西亞) | 
| ap-southeast-6 | 亞太區域 (紐西蘭) | 
| ap-southeast-7 | 亞太區域 (泰國) | 
| ca-central-1 | 加拿大 (中部) | 
| ca-west-1 | 加拿大西部 (卡加利) | 
| eu-central-1 | 歐洲 (法蘭克福) | 
| eu-central-2 | 歐洲 (蘇黎世) | 
| eu-north-1 | 歐洲 (斯德哥爾摩) | 
| eu-south-1 | 歐洲 (米蘭) | 
| eu-south-2 | 歐洲 (西班牙) | 
| eu-west-1 | 歐洲 (愛爾蘭) | 
| eu-west-2 | 歐洲 (倫敦) | 
| eu-west-3 | Europe (Paris) | 
| il-central-1 | 以色列 (特拉維夫) | 
| mx-central-1 | 墨西哥 (中部) | 
| sa-east-1 | 南美洲 (聖保羅) | 

**Topics**
+ [存取控制](#s3-tables-access-controls)
+ [自動掛載的目錄階層](#s3-tables-catalog-hierarchy)
+ [支援的區域](#s3-tables-supported-regions)
+ [先決條件](s3tables-catalog-prerequisites.md)
+ [啟用 S3 Tables 與 Data Catalog 整合](enable-s3-tables-catalog-integration.md)
+ [將資料庫和資料表新增至 S3 Tables 目錄](create-databases-tables-s3-catalog.md)
+ [共用 S3 Tables 目錄物件](share-s3-tables-catalog.md)
+ [管理 S3 Tables 整合](manage-s3-tables-catalog-integration.md)

# 先決條件
<a name="s3tables-catalog-prerequisites"></a>

在 AWS Glue Data Catalog 中建立 S3 Tables 的聯合型錄之前，請確定您的 IAM 主體 （使用者或角色） 具有必要的許可。

## 所需的 IAM 許可
<a name="s3tables-required-iam-permissions"></a>

您的 IAM 主體需要下列許可才能啟用 S3 Tables 整合：

**AWS Glue 許可**：
+ `glue:CreateCatalog` – `s3tablescatalog` 建立聯合目錄時需要
+ `glue:GetCatalog` – 檢視目錄詳細資訊時需要
+ `glue:GetDatabase` – 將 S3 命名空間檢視為資料庫時需要
+ `glue:GetTable` – 檢視 S3 資料表時需要
+ `glue:passConnection` – 授予呼叫委託人將`aws:s3tables`連線委派給 AWS Glue 服務的權利

**S3 Tables 許可** （用於 IAM 存取控制）：
+ `s3tables:CreateTableBucket`
+ `s3tables:GetTableBucket`
+ `s3tables:CreateNamespace`
+ `s3tables:GetNamespace`
+ `s3tables:ListNamespaces`
+ `s3tables:CreateTable`
+ `s3tables:GetTable`
+ `s3tables:ListTables`
+ `s3tables:UpdateTableMetadataLocation`
+ `s3tables:GetTableMetadataLocation`
+ `s3tables:GetTableData`
+ `s3tables:PutTableData`

## IAM 政策範例
<a name="s3tables-iam-policy-example"></a>

下列 IAM 政策提供在 IAM 模式中啟用 S3 Tables 與 Data Catalog 整合所需的最低許可：

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "GlueDataCatalogPermissions",
      "Effect": "Allow",
      "Action": [
        "glue:CreateCatalog",
        "glue:GetCatalog",
        "glue:GetDatabase",
        "glue:GetTable"
      ],
      "Resource": [
        "arn:aws:glue:region:account-id:catalog/s3tablescatalog",
        "arn:aws:glue:region:account-id:database/s3tablescatalog/*/*",
        "arn:aws:glue:region:account-id:table/s3tablescatalog/*/*/*"
      ]
    },
    {
      "Sid": "S3TablesDataAccessPermissions",
      "Effect": "Allow",
      "Action": [
        "s3tables:GetTableBucket",
        "s3tables:GetNamespace",
        "s3tables:GetTable",
        "s3tables:GetTableMetadataLocation",
        "s3tables:GetTableData"
      ],
      "Resource": [
        "arn:aws:s3tables:region:account-id:bucket/*",
        "arn:aws:s3tables:region:account-id:bucket/*/table/*"
      ]
    }
  ]
}
```

# 啟用 S3 Tables 與 Data Catalog 整合
<a name="enable-s3-tables-catalog-integration"></a>

您可以使用 Amazon S3 管理主控台或 啟用與 AWS Glue Data Catalog 的 S3 Tables 整合 AWS CLI。 Amazon S3 當您使用主控台啟用整合時， 會 AWS 建立名為 的聯合目錄`s3tablescatalog`，自動探索和掛載 AWS 帳戶和區域中的所有 S3 資料表儲存貯體。

## 使用 Amazon S3 管理主控台啟用 S3 Tables 整合 Amazon S3
<a name="enable-s3-tables-console"></a>

1. 開啟位於 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/) 的 Amazon S3 主控台。

1. 在左側導覽窗格中，選擇**資料表儲存貯體**。

1. 選擇 **建立資料表儲存貯體**。

1. 輸入**資料表儲存貯體名稱**，並確認已選取**啟用整合**核取方塊。

1. 選擇 **建立資料表儲存貯體**。

Amazon S3 會自動整合您在該區域中的資料表儲存貯體。您第一次在任何區域中整合資料表儲存貯體時，Amazon S3 `s3tablescatalog`會在該區域中的資料目錄中建立 。

建立目錄後，帳戶和區域中的所有 S3 資料表儲存貯體都會自動掛載為子目錄。您可以透過導覽至 Data Catalog 中的目錄來檢視資料庫 （命名空間） 和資料表。

## 使用 啟用 S3 Tables 整合 AWS CLI
<a name="enable-s3-tables-cli"></a>

使用 `glue create-catalog`命令來建立`s3tablescatalog`目錄。

```
aws glue create-catalog \
  --name "s3tablescatalog" \
  --catalog-input '{
    "Description": "Federated catalog for S3 Tables",
    "FederatedCatalog": {
      "Identifier": "arn:aws:s3tables:region:account-id:bucket/*",
      "ConnectionName": "aws:s3tables"
    },
    "CreateDatabaseDefaultPermissions": [{
      "Principal": {
        "DataLakePrincipalIdentifier": "IAM_ALLOWED_PRINCIPALS"
      },
      "Permissions": ["ALL"]
    }],
    "CreateTableDefaultPermissions": [{
      "Principal": {
        "DataLakePrincipalIdentifier": "IAM_ALLOWED_PRINCIPALS"
      },
      "Permissions": ["ALL"]
    }]
  }'
```

將*區域*取代為 AWS 區域，將*帳戶 ID *取代為 AWS 帳戶 ID。

## 驗證整合
<a name="verify-s3-tables-integration"></a>

建立目錄後，您可以透過列出子目錄來驗證 S3 資料表儲存貯體是否已掛載：

```
aws glue get-catalogs \
  --parent-catalog-id s3tablescatalog
```

# 將資料庫和資料表新增至 S3 Tables 目錄
<a name="create-databases-tables-s3-catalog"></a>

請確定您擁有必要的許可，以列出和建立 區域中 Data Catalog 中的目錄、資料庫和資料表。確保已在 AWS 您的帳戶和區域中啟用 S3 Tables 整合。

## 將資料庫新增至 S3 Tables 目錄
<a name="add-database-s3-tables-catalog"></a>

### 新增資料庫 （主控台）
<a name="add-database-s3-tables-console"></a>

1. 在 https：//[https://console.aws.amazon.com/glue/home](https://console.aws.amazon.com/glue/home) 開啟 AWS Glue 主控台。

1. 在左側的導覽窗格中，選擇**資料庫**。

1. 選擇**新增資料庫**。

1. **在 S3 Tables 聯合目錄中選擇 Glue 資料庫**。

1. 輸入資料庫的唯一名稱。

1. 選取映射至 S3 Tables 中資料表儲存貯體的目標目錄。

1. 選擇 **Create Database (建立資料庫)**。

### 新增資料庫 (AWS CLI)
<a name="add-database-s3-tables-cli"></a>

```
aws glue create-database \
  --region region \
  --catalog-id "account-id:s3tablescatalog/my-catalog" \
  --database-input '{"Name": "my-database"}'
```

## 將資料表新增至 S3 Tables 目錄
<a name="add-table-s3-tables-catalog"></a>

### 新增資料表 （主控台）
<a name="add-table-s3-tables-console"></a>

1. 在 https：//[https://console.aws.amazon.com/glue/home](https://console.aws.amazon.com/glue/home) 開啟 AWS Glue 主控台。

1. 在左側導覽窗格中，選擇 **Tables (資料表)**。

1. 在目錄下拉式清單中選取適當的 S3 Tables 目錄。

1. 選擇**新增資料表**。

1. 輸入資料表的唯一名稱。

1. 在目錄下拉式清單中確認已選取正確的 S3 Tables 目錄。

1. 在資料庫下拉式清單中選取資料庫。

1. 透過輸入 JSON 或個別新增每個資料欄來輸入資料表結構描述。

1. 選擇 **Create Table** (建立資料表)。

### 新增資料表 (AWS CLI)
<a name="add-table-s3-tables-cli"></a>

```
aws glue create-table \
  --region region \
  --catalog-id "account-id:s3tablescatalog/my-catalog" \
  --database-name "my-database" \
  --table-input '{
    "Name": "my-table",
    "Parameters": {
      "classification": "",
      "format": "ICEBERG"
    },
    "StorageDescriptor": {
      "Columns": [
        {"Name": "id", "Type": "int", "Parameters": {}},
        {"Name": "val", "Type": "string", "Parameters": {}}
      ]
    }
  }'
```

# 共用 S3 Tables 目錄物件
<a name="share-s3-tables-catalog"></a>

使用 IAM 存取控制時，您可以使用相同帳戶共用 AWS Glue 的資源連結，與其他使用者共用 S3 Tables 目錄物件。對於跨帳戶共用，您可以與其他 AWS 帳戶共用 S3 資料表儲存貯體，而且收件人帳戶中的 IAM 角色或使用者可以使用共用資料表儲存貯體建立 AWS Glue 目錄物件。

## 使用資源連結在相同帳戶中共用
<a name="share-s3-tables-resource-links"></a>

資源連結可讓您在 AWS Glue 預設目錄中顯示的 中建立 AWS Glue 資料庫和資料表`s3tablescatalog`的參考。這有助於組織資料存取或建立資料表的邏輯分組。

### 建立資源連結 （主控台）
<a name="share-s3-tables-resource-link-console"></a>

1. 在 https：//[https://console.aws.amazon.com/glue/](https://console.aws.amazon.com/glue/) 開啟 AWS Glue 主控台。

1. 在導覽窗格中，選擇**目錄**。

1. 在**目錄**清單中，選取 **s3tablescatalog**。

1. 從 選取您要共用的資料表`s3tablescatalog`。

1. 選擇**動作**，然後選擇**建立資源連結**。

1. 針對**資源連結名稱**，輸入資源連結的名稱。

1. 針對**目標資料庫**，選取您要建立資源連結的資料庫。

1. 在**描述**，請輸入描述。

1. 選擇**建立**。

資源連結會出現在目標資料庫中，並指向 中的原始資料表`s3tablescatalog`。

### 建立資源連結 (AWS CLI)
<a name="share-s3-tables-resource-link-cli"></a>

建立資料庫資源連結：

```
aws glue create-database \
  --database-name "my-database-resource-link" \
  --database-input '{
    "Name": "sales_data_link",
    "TargetDatabase": {
      "CatalogId": "account-id:s3tablescatalog/analytics-bucket",
      "DatabaseName": "sales"
    }
  }'
```

建立資料表資源連結：

```
aws glue create-table \
  --table-name "my-table-resource-link" \
  --table-input '{
    "Name": "sales_data_link",
    "TargetTable": {
      "CatalogId": "account-id:s3tablescatalog/analytics-bucket",
      "DatabaseName": "sales",
      "Name": "transactions"
    }
  }'
```

# 管理 S3 Tables 整合
<a name="manage-s3-tables-catalog-integration"></a>

## 啟用 AWS Lake Formation
<a name="manage-s3-tables-enable-lf"></a>

當您想要擴展資料控管需求時，您可以 AWS Lake Formation 為 S3 Tables 目錄啟用 。 AWS Lake Formation 提供資料庫樣式的授予，以管理精細的存取、使用標籤型存取擴展許可，以及根據使用者屬性授予許可，例如 S3 Tables 中資料表的群組關聯。

前往 AWS Lake Formation 管理主控台， AWS Lake Formation 為您的 S3 Tables 目錄啟用 AWS Glue。如需詳細資訊，請參閱《 *AWS Lake Formation 開發人員指南*》中的[建立 S3 資料表目錄](https://docs.aws.amazon.com/lake-formation/latest/dg/create-s3-tables-catalog.html)。

## 刪除 S3 Tables 整合
<a name="manage-s3-tables-delete-integration"></a>

您可以透過刪除 Data Catalog 中的目錄整合來刪除 S3 Tables 整合。此操作只會刪除 Data Catalog 中的中繼資料，不會刪除 S3 Tables 中的資源。

確保您擁有列出、編輯和刪除目錄物件的必要許可 AWS Glue。

### 刪除整合 （主控台）
<a name="delete-s3-tables-console"></a>

1. 在 https：//[https://console.aws.amazon.com/glue/home](https://console.aws.amazon.com/glue/home) 開啟 AWS Glue 主控台。

1. 在導覽窗格中，選擇**目錄**。

1. 在**目錄**清單中，選取 **s3tablescatalog**。

1. 選擇 **刪除**。

1. 確認刪除目錄也會刪除資料目錄中所有相關聯的目錄物件。

1. 選擇 **刪除**。

### 刪除整合 (AWS CLI)
<a name="delete-s3-tables-cli"></a>

```
aws glue delete-catalog \
  --region region \
  --catalog-id "s3tablescatalog"
```