

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

# Amazon S3 Tables 與 AWS Glue Data Catalog 和 整合 AWS Lake Formation
<a name="create-s3-tables-catalog"></a>

[Amazon S3 Tables](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables.html) 提供專門針對分析工作負載最佳化的 S3 儲存體，可改善查詢效能，同時降低成本。S3 Tables 中的資料會存放在新的儲存貯體類型中：*資料表儲存貯體*，其會將資料表儲存為子資源。S3 資料表內建支援 Apache Iceberg 標準，可讓您使用常見的查詢引擎，例如 Apache Spark，輕鬆查詢 Amazon S3 資料表儲存貯體中的表格式資料。

您可以使用 IAM AWS Glue Data Catalog 存取控制或 IAM 和 Lake Formation 授予，將 Amazon S3 Tables 與 整合：
+ **IAM 存取控制**：使用 IAM 政策來控制對 S3 Tables 和 Data Catalog 的存取。在此存取控制方法中，您需要 S3 Tables 資源和 Data Catalog 物件的 IAM 許可，才能存取資源。
+ **Lake Formation 存取控制**：除了 IAM AWS Glue 許可之外，還使用 AWS Lake Formation 授予來控制透過 Data Catalog 對 S3 Tables 的存取。在此模式中，主體需要 IAM 許可才能與 Data Catalog 互動，Lake Formation 授予會決定主體可存取的目錄資源 （資料庫、資料表、資料欄、資料列）。此模式同時支援粗粒存取控制 （資料庫層級和資料表層級授予） 和精細存取控制 （資料欄層級和資料列層級安全性）。設定已註冊角色並啟用憑證販賣時，委託人不需要 S3 Tables IAM 許可，因為 Lake Formation 會使用已註冊角色代表委託人提供憑證。Lake Formation 存取控制也支援第三方分析引擎的憑證販賣。

本節提供針對 AWS Lake Formation 下列案例設定與 整合的指引：
+ **案例 A**：您使用 IAM 存取控制整合 S3 資料表和資料目錄，現在計劃使用 AWS Lake Formation。如需進一步了解，請參閱[變更 S3 Tables 整合的存取控制](manage-s3tables-catalog-integration.md)。
+ **案例 B**：您計劃使用 整合 S3 Tables 和 Data Catalog AWS Lake Formation ，而且目前不會在您的帳戶和區域中整合它們。從 [將 Amazon S3 資料表目錄與 Data Catalog 和 Lake Formation 整合的先決條件](s3tables-catalog-prerequisites.md)區段開始，並遵循 [啟用 Amazon S3 Tables 整合](enable-s3-tables-catalog-integration.md)。
+ **案例 C**：您使用 整合 S3 資料表和資料目錄 AWS Lake Formation ，現在計劃使用 IAM。如需進一步了解，請參閱[變更 S3 Tables 整合的存取控制](manage-s3tables-catalog-integration.md)。

請務必遵循[將 S3 資料表與 AWS 分析服務整合](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-integrating-aws.html)中的步驟，以便您擁有適當的許可來存取 AWS Glue Data Catalog 和資料表資源，以及使用 AWS 分析服務。

**Topics**
+ [Data Catalog 和 Lake Formation 整合的運作方式](#w2aac13c27c19)
+ [將 Amazon S3 資料表目錄與 Data Catalog 和 Lake Formation 整合的先決條件](s3tables-catalog-prerequisites.md)
+ [啟用 Amazon S3 Tables 整合](enable-s3-tables-catalog-integration.md)
+ [在 S3 資料表目錄中建立資料庫和資料表](create-databases-tables-s3-catalog.md)
+ [在另一個 AWS 帳戶中註冊 Amazon S3 資料表儲存貯體](register-cross-account-s3-table-bucket.md)
+ [授予許可](s3-tables-grant-permissions.md)

## Data Catalog 和 Lake Formation 整合的運作方式
<a name="w2aac13c27c19"></a>

當您將 S3 資料表目錄與 Data Catalog 和 Lake Formation 整合時， AWS Glue 服務會在您帳戶的預設 Data Catalog `s3tablescatalog`中建立名為 的單一聯合目錄 AWS 區域。整合會以下列方式映射您帳戶和聯合目錄 AWS 區域 下的所有 Amazon S3 資料表儲存貯體資源：
+ Amazon S3 資料表儲存貯體會成為 Data Catalog 中的多層級目錄。
+ 相關聯的 Amazon S3 命名空間會在 Data Catalog 中註冊為資料庫。
+ 資料表儲存貯體中的 Amazon S3 資料表會成為資料目錄中的資料表。

![\[S3 Tables 和 之間的物件映射 AWS Glue Data Catalog。\]](http://docs.aws.amazon.com/zh_tw/lake-formation/latest/dg/images/S3Tables-glue-catalog.png)


 與 Lake Formation 整合後，您可以在資料表儲存貯體目錄中建立 Apache Iceberg 資料表，並透過整合的 AWS 分析引擎存取它們 Amazon Athena，例如 Amazon EMR 和第三方分析引擎。

當您也啟用 Lake Formation 與整合時，它會透過 啟用精細存取控制 AWS Lake Formation。此安全方法表示，除了 (IAM) 許可之外 AWS Identity and Access Management ，您還必須在資料表上授予具有 Lake Formation 許可的 IAM 主體，才能使用這些許可。

 AWS Lake Formation中有兩種主要類型的權限：
+ 中繼資料存取權限可控制在 Data Catalog 中建立、讀取、更新和刪除中繼資料資料庫和資料表的能力。
+ 基礎資料存取權限可控制讀取和寫入資料目錄資源指向的基礎 Amazon S3 位置的能力。

Lake Formation 使用自己的許可模型和 IAM 許可模型的組合，控制對 Data Catalog 資源和基礎資料的存取：
+ 若要請求成功存取 Data Catalog 資源或基礎資料，則請求必須通過 IAM 和 Lake Formation 的許可權檢查。
+ IAM 許可控制對 Lake Formation 和 AWS Glue APIs存取，而 Lake Formation 許可控制對 Data Catalog 資源、Amazon S3 位置和基礎資料的存取。

Lake Formation 許可權僅適用於授予其獲授權的區域，且主體必須由資料湖管理員或其他具有必要權限的主體的授權，才能授予 Lake Formation 許可。

# 將 Amazon S3 資料表目錄與 Data Catalog 和 Lake Formation 整合的先決條件
<a name="s3tables-catalog-prerequisites"></a>

以下是啟用 Amazon S3 資料表與 AWS Glue Data Catalog 和 整合的先決條件 AWS Lake Formation。

1.  當您啟用 Amazon S3 資料表整合時，Lake Formation 會自動註冊 S3 資料表的位置。若要向 Lake Formation 註冊資料表儲存貯體位置，您需要具有 `lakeformation:RegisterResource`、 `lakeformation:RegisterResourceWithPrivilegedAccess`和 `lakeformation:CreateCatalog`許可的 IAM 角色/使用者。當具有這些許可的非管理員使用者註冊目錄位置時，Lake Formation 會自動授予他們該位置的`DATA_LOCATION_ACCESS`許可，允許呼叫委託人在已註冊的資料位置上執行所有支援的 Lake Formation 操作。

1. <a name="step3-permissions"></a> 當您啟用 S3 資料表整合時，您需要為 Lake Formation 選擇 IAM 角色來提供登入資料，以允許資料存取。為對 S3 資料表儲存貯體的 Lake Formation 資料存取建立 IAM 角色。向 Lake Formation 註冊資料表儲存貯體時使用的 IAM 角色需要下列許可：

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "LakeFormationPermissionsForS3ListTableBucket",
               "Effect": "Allow",
               "Action": [
                   "s3tables:ListTableBuckets"
               ],
               "Resource": [
                   "*"
               ]
           },
           {
               "Sid": "LakeFormationDataAccessPermissionsForS3TableBucket",
               "Effect": "Allow",
               "Action": [
                   "s3tables:CreateTableBucket",
                   "s3tables:GetTableBucket",
                   "s3tables:CreateNamespace",
                   "s3tables:GetNamespace",
                   "s3tables:ListNamespaces",
                   "s3tables:DeleteNamespace",
                   "s3tables:DeleteTableBucket",
                   "s3tables:CreateTable",
                   "s3tables:DeleteTable",
                   "s3tables:GetTable",
                   "s3tables:ListTables",
                   "s3tables:RenameTable",
                   "s3tables:UpdateTableMetadataLocation",
                   "s3tables:GetTableMetadataLocation",
                   "s3tables:GetTableData",
                   "s3tables:PutTableData"
               ],
               "Resource": [
                   "arn:aws:s3tables:us-east-1:123456789012:bucket/*"
               ]
           }
       ]
   }
   ```

------

   如需詳細資訊，請參閱[用於註冊位置的角色需求](registration-role.md)。

1.  將下列信任政策新增至 IAM 角色，以允許 Lake Formation 服務擔任角色，並將臨時憑證提供給整合的分析引擎。

   ```
   {
     "Effect": "Allow",
     "Principal": {
       "Service": "lakeformation.amazonaws.com"
     },
     "Action": [
       "sts:AssumeRole",
       "sts:SetSourceIdentity",
       "sts:SetContext"  # add action to trust relationship when using IAM Identity center principals with Lake Formation
     ]
   }
   ```

**注意**  
 AWS 分析服務整合程序已更新。如果您已設定與預覽版本的整合，您可以繼續使用目前的整合。不過，更新的整合程序可提供效能改善。若要更新整合：  
首先，刪除 Lake Formation 中現有的 S3 資料表目錄。若要刪除目錄，請從`s3tablescatalog`目錄清單中選取目錄，然後選擇從**動作****中刪除**。
接著，取消註冊 的資料位置`s3tablescatalog`。  
在 Lake Formation 主控台的**管理**區段下，選擇**資料位置**。
選取位置，然後從**動作**功能表中選擇**移除**。
出現確認提示時，請選擇**移除**。  
如需取消註冊資料位置的詳細說明，請參閱 [取消註冊 Amazon S3 位置](unregister-location.md)一節。
然後，遵循 [啟用 Amazon S3 Tables 整合](enable-s3-tables-catalog-integration.md)區段中的更新整合步驟。

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

您可以使用 Amazon S3 主控台建立 Amazon S3 資料表儲存貯體，並將其與 AWS 分析服務整合。如需詳細資訊，請參閱[搭配 AWS 分析服務使用 Amazon S3 Tables](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-integrating-aws.html)。

 在 中 AWS Lake Formation，您可以使用 Lake Formation 主控台或使用 啟用與 AWS Glue Data Catalog 和 的 Amazon S3 Tables AWS Lake Formation 整合 AWS CLI。

## 將 Amazon S3 Tables 與 Data Catalog 和 Lake Formation （主控台） 整合
<a name="w2aac13c27c23b7b1"></a>

1. 開啟 Lake Formation 主控台，網址為 [https://console.aws.amazon.com/lakeformation/](https://console.aws.amazon.com/lakeformation/)。

1. 在導覽窗格中，選擇資料**目錄**下的目錄。 ****

1. 在**目錄**頁面上選擇**啟用 S3 資料表整合**。  
![\[目錄頁面上的啟用 S3 資料表整合選項。\]](http://docs.aws.amazon.com/zh_tw/lake-formation/latest/dg/images/enable-s3-table-integration.png)

1.  選擇具有 Lake Formation 所需許可的 IAM 角色，以擔任將登入資料提供給分析查詢引擎。如需角色存取資料所需的許可，請參閱先決條件一節[step3-permissions](s3tables-catalog-prerequisites.md#step3-permissions)中的 。  
![\[啟用具有 IAM 角色的 S3 整合畫面。\]](http://docs.aws.amazon.com/zh_tw/lake-formation/latest/dg/images/enable-s3-table-catalog.png)

1.  選取**允許外部引擎使用完整資料表存取選項存取 Amazon S3 位置中的資料**。當您為第三方引擎啟用完整資料表存取時，Lake Formation 會直接將登入資料傳回給第三方引擎，而不執行 IAM 工作階段標籤驗證。這表示您無法將 Lake Formation 精細存取控制套用至要存取的資料表。

1. 選擇**啟用**。S3 Tables 的新目錄會新增至目錄清單。當您啟用 S3 資料表目錄整合時，服務會向 Lake Formation 註冊 S3 資料表儲存貯體的資料位置。

1. 選擇目錄以檢視目錄物件，並將許可授予其他主體。  
![\[S3 資料表目錄\]](http://docs.aws.amazon.com/zh_tw/lake-formation/latest/dg/images/s3-table-catalog.png)

   若要建立多層級目錄，請參閱《Amazon Simple Storage Service 使用者指南》中的[建立資料表儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-buckets-create.html)體一節。

## 將 Amazon S3 資料表與資料目錄和 Lake Formation (CLI) 整合
<a name="w2aac13c27c23b7b3"></a>

在先決條件區段之後，建立允許 Lake Formation 存取資料表資源的 IAM 服務角色。

1. 建立名為 `Role-Trust-Policy.json` 的檔案，其中包含下列信任政策：

   ```
   {
       "Version": "2012-10-17",		 	 	 
       "Statement": [
         {
           "Sid": "LakeFormationDataAccessPolicy",
           "Effect": "Allow",
           "Principal": {
             "Service": "lakeformation.amazonaws.com"
           },
           "Action": [
               "sts:AssumeRole",
               "sts:SetContext",
               "sts:SetSourceIdentity"
           ],
           "Condition": {
             "StringEquals": {
               "aws:SourceAccount": "111122223333"
             }
           }
         }
       ]
   }
   ```

1. 使用下列命令建立 IAM 服務角色：

   ```
   aws iam create-role \
     --role-name S3TablesRoleForLakeFormation \
     --assume-role-policy-document file://Role-Trust-Policy.json
   ```

1. 建立包含下列政策之名為 `LF-GluePolicy.json` 的檔案：

   ```
   {
       "Version": "2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "LakeFormationPermissionsForS3ListTableBucket",
               "Effect": "Allow",
               "Action": [
                   "s3tables:ListTableBuckets"
               ],
               "Resource": [
                   "*"
               ]
           },
           {
               "Sid": "LakeFormationDataAccessPermissionsForS3TableBucket",
               "Effect": "Allow",
               "Action": [
                   "s3tables:CreateTableBucket",
                   "s3tables:GetTableBucket",
                   "s3tables:CreateNamespace",
                   "s3tables:GetNamespace",
                   "s3tables:ListNamespaces",
                   "s3tables:DeleteNamespace",
                   "s3tables:DeleteTableBucket",
                   "s3tables:CreateTable",
                   "s3tables:DeleteTable",
                   "s3tables:GetTable",
                   "s3tables:ListTables",
                   "s3tables:RenameTable",
                   "s3tables:UpdateTableMetadataLocation",
                   "s3tables:GetTableMetadataLocation",
                   "s3tables:GetTableData",
                   "s3tables:PutTableData"
               ],
               "Resource": [
                   "arn:aws:s3tables:us-east-1:111122223333:bucket/*"
               ]
           }
       ]
   }
   ```

1. 使用下列命令以將政策連接至角色：

   ```
   aws iam put-role-policy \
     --role-name S3TablesRoleForLakeFormation \
     --policy-name LakeFormationDataAccessPermissionsForS3TableBucket \
     --policy-document file://LF-GluePolicy.json
   ```

1. 建立包含下列內容之名為 `input.json` 的檔案：

   ```
   {
       "ResourceArn": "arn:aws:s3tables:us-east-1:111122223333:bucket/*",
       "WithFederation": true,
       "RoleArn": "arn:aws:iam::111122223333:role/S3TablesRoleForLakeFormation"
   }
   ```

1. 使用下列命令向 Lake Formation 註冊資料表儲存貯體：

   ```
   aws lakeformation register-resource \
     --region us-east-1 \
     --with-privileged-access \
     --cli-input-json file://input.json
   ```

1. 建立包含下列型錄之名為 `catalog.json` 的檔案：

   ```
   {
      "Name": "s3tablescatalog",
      "CatalogInput": {
         "FederatedCatalog": {
             "Identifier": "arn:aws:s3tables:us-east-1:111122223333:bucket/*",
             "ConnectionName": "aws:s3tables"
          },
          "CreateDatabaseDefaultPermissions": [],
          "CreateTableDefaultPermissions": [],
          "AllowFullTableExternalDataAccess": "True"
      }
   }
   ```

1. 使用下列命令列來建立 `s3tablescatalog` 型錄。建立此目錄會將對應至資料表儲存貯體、命名空間和資料表的 AWS Glue Data Catalog 物件填入 。

   ```
   aws glue create-catalog \
     --region us-east-1 \
     --cli-input-json file://catalog.json
   ```

1.  AWS Glue 使用以下命令確認`s3tablescatalog`目錄已新增至 ：

   ```
   aws glue get-catalog --catalog-id s3tablescatalog
   ```

# 在 S3 資料表目錄中建立資料庫和資料表
<a name="create-databases-tables-s3-catalog"></a>

 您可以建立資料庫來組織 Apache Iceberg 資料表，以及建立資料表來定義 S3 資料表目錄中資料的結構描述和位置。

## 建立資料庫 （主控台）
<a name="w2aac13c27c25b5b1"></a>

1.  在 https：//[https://console.aws.amazon.com/lakeformation/](https://console.aws.amazon.com/lakeformation/) 開啟 Lake Formation 主控台，並以資料湖管理員或資料庫建立者身分登入。

1. 在導覽窗格中，選擇 **Data Catalog** **下的資料庫**。

1. 選擇**建立資料庫**。

1.  在**建立資料庫**頁面上，選擇**資料庫**選項，然後輸入下列詳細資訊：
   + **名稱 **– 資料庫的唯一名稱
   + **資料目錄** – 選擇 S3 資料表目錄。資料庫將位於此目錄中。
   + **描述** –（選用） 新增描述和位置。
   + **新資料表的 IAM 存取控制** – 選擇性地選取僅對此資料庫中的新資料表使用 IAM 存取控制。如需此選項的相關資訊，請參閱[變更資料湖的預設設定](https://docs.aws.amazon.com/lake-formation/latest/dg/change-settings.html)一節。
   + 選擇**建立資料庫**。您可以查看在 S3 資料表目錄下建立的資料庫。

## 使用 建立資料庫 AWS CLI
<a name="w2aac13c27c25b5b3"></a>

下列 CLI 命令顯示如何在 S3 資料表目錄中建立資料庫。

```
aws glue create-database 
--region us-east-1 \
--catalog-id "123456789012:s3tablescatalog/test" \
--database-input \
 '{ "Name": "testglueclidbcreation" }'
```

## 建立資料表 (AWS 管理主控台)
<a name="w2aac13c27c25b5b5"></a>

 您可以使用 Lake Formation 主控台或 API，在 S3 資料表目錄中建立 Apache Iceberg AWS Glue `CreateTable`中繼資料表。

1. 開啟 Lake Formation 主控台，網址為 [https://console.aws.amazon.com/lakeformation/](https://console.aws.amazon.com/lakeformation/)：//`CreateTable`。

1. 在導覽窗格中，選擇 Data Catalog **下的資料表**。

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

1. 在**建立資料表**頁面上，輸入資料表詳細資訊：  
![\[S3 資料表目錄\]](http://docs.aws.amazon.com/zh_tw/lake-formation/latest/dg/images/s3-catalog-create-table.png)
   + **名稱 **– 輸入資料表的唯一名稱。
   + **目錄** – 選擇 S3 資料表目錄做為目錄。
   + **資料庫** – 選擇 S3 資料表目錄下的資料庫。
   +  **描述** – 輸入資料表的描述。
   + **結構描述** – 選擇新增資料欄以新增資料欄和資料欄的資料類型。可以選擇建立空白資料表，稍後再更新結構描述。Iceberg 可讓您在建立資料表之後改進結構描述和分區。可以使用 Athena 查詢來更新資料表結構描述，使用 Spark 查詢來更新分區。

1. 選擇**提交**。

## 建立資料表 (AWS CLI)
<a name="w2aac13c27c25b5b7"></a>

```
aws glue create-table \ 
--database-name "testglueclidbcreation" \ 
--catalog-id "123456789012:s3tablescatalog/test" \ 
--region us-east-1 \ 
--table-input \ 
'{ "Name": "testtablegluecli", "Parameters": { "format": "ICEBERG" }, "StorageDescriptor": { "Columns": [ {"Name": "x", "Type": "int", "Parameters": {"required": "true"}} ] } }'
```

# 在另一個 AWS 帳戶中註冊 Amazon S3 資料表儲存貯體
<a name="register-cross-account-s3-table-bucket"></a>

您可以從另一個 AWS 帳戶中的 Lake Formation 帳戶註冊個別 Amazon S3 資料表儲存貯體 (ARN 格式：`arn:aws:s3tables:us-east-1:account-id:bucket/bucket-name`)。例如，您可以從帳戶 B Lake Formation 中的帳戶 A 註冊資料表儲存貯體。

## 先決條件
<a name="w2aac13c27c27b5"></a>

開始跨帳戶儲存貯體註冊之前：
+ 在帳戶 A 中建立資料表儲存貯體。
+ 在帳戶 B 中建立具有儲存貯體註冊適當許可的 IAM 角色。

  如需向 Lake Formation 註冊資料表儲存貯體所需許可的詳細資訊，請參閱 [將 Amazon S3 資料表目錄與 Data Catalog 和 Lake Formation 整合的先決條件](s3tables-catalog-prerequisites.md)。
+ 在您要建立 S3 資料表目錄的帳戶中註冊資料表儲存貯體。
+  對於跨帳戶存取，註冊資料表儲存貯體時指定的角色必須是具有適當許可的帳戶內角色，才能存取跨帳戶儲存貯體。此角色需要必要的 S3 Tables IAM 動作才能存取儲存貯體資源。

## 跨帳戶資料表儲存貯體註冊
<a name="w2aac13c27c27b7"></a>

在下列程序中，帳戶 A 是擁有 帳戶的資源，而帳戶 B 是將註冊資料表儲存貯體以管理存取許可的位置。

1. 登入帳戶 A AWS 管理主控台 中的 。

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

1.  建立資料表儲存貯體。如需詳細資訊，請參閱《Amazon S3 使用者指南》中的[建立資料表儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-buckets-create.html)體。

1. 在帳戶 B 中註冊資料表儲存貯體。

   使用 從帳戶 A 向帳戶 B 中的 Lake Formation AWS CLI 註冊資料表儲存貯體。

   ```
   aws lakeformation register-resource \
   --resource-arn 'arn:aws:s3tables:us-east-1:account-A-id:bucket/single-bucket-name' \
   --role-arn arn:aws:iam::account-B-id:role/role-name \
   --region us-east-1
   ```

   將 account-A-id、single-bucket-name、account-B-id 和 role-name 取代為您的特定值。

1. 接著，為帳戶 B 中的資料表儲存貯體建立目錄。

   使用 建立目錄 AWS CLI。

   ```
   aws glue create-catalog --region us-east-1 \
   --cli-input-json \
   '{
      "Name": "catalog-name",
      "CatalogInput" : {
         "FederatedCatalog": {
            "Identifier": "arn:aws:s3tables:us-east-1:account A:bucket/single-bucket-name",
            "ConnectionName": "aws:s3tables"
         },
         "CreateDatabaseDefaultPermissions": [],
         "CreateTableDefaultPermissions": []      
      }
   }'
   ```

   將 catalog-name、account-A-id 和 bucket-name 取代為您的特定值。

    下列 CLI 範例示範如何檢視目錄的詳細資訊。

   ```
    aws glue get-catalog \
     --catalog-id account-id:catalog-name \
     --region us-east-1
   ```

1. 接著，在帳戶 B 中新建立的目錄中建立資料庫和資料表。

   建立資料庫。

   ```
   aws glue create-database \
     --region us-east-1 \
     --catalog-id "account-B-id:catalog-name" \
     --database-input \
   '{
     "Name": "database-name"
   }'
   ```

   建立資料表。

   ```
   aws glue create-table \
     --database-name database-name \
     --catalog-id account-B-id:catalog-name\
     --region us-east-1 \
     --table-input \
     '{
           "Name": "table-name",
           "Parameters": {
               "format": "ICEBERG"
           },
           "StorageDescriptor": {
              "Columns": [
           {"Name": "x", "Type": "int", "Parameters": {"required": "true"}}
             ]
           }
   }'
   ```

   將 database-name、account-B-id、 catalog-name 和 table-name 取代為您的特定值。

1. 下列範例示範如何檢視 目錄中的物件。

   檢視資料庫詳細資訊。

   ```
   aws glue get-database \
     --name database-name \
     --catalog-id account-B-id:catalog-name \
     --region us-east-1
   ```

   檢視資料表詳細資訊。

   ```
   aws glue get-table \
     --name table-name \
     --database-name database-name \
     --catalog-id account-B-id:catalog-name \
     --region us-east-1
   ```

   將 database-name、account-B-id、 catalog-name 和 table-name 取代為您的特定值。

# 授予許可
<a name="s3-tables-grant-permissions"></a>

 將 S3 資料表與 整合之後 AWS Lake Formation，您可以將 S3 資料表目錄和目錄物件 （資料表儲存貯體、資料庫、資料表） 的許可授予帳戶中的其他 IAM 角色和使用者。Lake Formation 許可可讓您為 Amazon Redshift Spectrum 和 Athena 等整合分析引擎的使用者定義資料表、資料欄和資料列層級精細度的存取控制。

 您可以使用具名資源方法或 Lake Formation 標籤型存取控制 (LF-TBAC) 方法來授予許可。使用 LF-Tags 和 LF-Tag 表達式授予許可之前，您必須定義它們並將其命名為 Data Catalog 物件。

如需詳細資訊，請參閱[管理中繼資料存取控制的 LF 標籤](managing-tags.md)。

您可以透過將 Lake Formation 許可授予外部 AWS 帳戶，與外部帳戶共用資料庫和資料表。然後，使用者可以執行查詢和任務，以跨多個帳戶聯結和查詢資料表。當您與其他 帳戶共用目錄資源時，該帳戶中的主體可以操作該資源，就像資源在其資料目錄中一樣。

當您與外部帳戶共用資料庫和資料表時，無法使用**超級使用者**許可。

 如需授予許可的詳細說明，請參閱 [管理 Lake Formation 許可](managing-permissions.md)一節。

## AWS CLI 授予 Amazon S3 資料表許可的範例
<a name="w2aac13c27c29c15"></a>

```
aws lakeformation grant-permissions \
--cli-input-json \
'{
    "Principal": {
        "DataLakePrincipalIdentifier":"arn:aws:iam::111122223333:role/DataAnalystRole"
    },
    "Resource": {
        "Table": {
            "CatalogId":"111122223333:s3tablescatalog/amzn-s3-demo-bucket1",
            "DatabaseName":"S3 table bucket namespace <example_namespace>",
            "Name":"S3 table bucket table name <example_table>"
        }
    },
    "Permissions": [
        "SELECT"
    ]
}'
```

 以下是要包含在 命令中的參數：
+ DataLakePrincipalIdentifier – IAM 使用者、角色或群組 ARN 授予許可
+ CatalogId – 擁有 Data Catalog 的 12 位數 AWS 帳戶 ID
+ DatabaseName – Amazon S3 資料表儲存貯體名稱空間的名稱
+ 名稱 – Amazon S3 資料表儲存貯體資料表名稱
+ 許可 – 授予的許可。選項包括：SELECT、INSERT、DELETE、DESCRIBE、ALTER、DROP、ALLL 和 SUPER

# 存取共用的 Amazon S3 資料表
<a name="s3-tables-cross-account-sharing"></a>

 在 S3 資料表目錄中授予資料庫或資料表的跨帳戶許可後，若要存取資源，您需要建立共用資料庫和資料表的資源連結。

1.  在目的地帳戶 （接收共用資源的帳戶） 中，建立資料庫資源連結。如需詳細說明，請參閱 [建立共用 Data Catalog 資料庫的資源連結](create-resource-link-database.md)。

   建立資料庫資源連結的 CLI 範例

   ```
   aws glue create-database 
   --region us-east-1 
   --catalog-id "111122223333" 
   --database-input \
   '{
     "Name": "s3table_resourcelink",
     "TargetDatabase": {
       "CatalogId": "011426214932:s3tablescatalog/chmni-s3-table-bucket-011426214932",
       "DatabaseName": "s3_table_ns"
     },
     "CreateTableDefaultPermissions": []
   }'
   ```

1.  在資料表上授予跨帳戶許可。

   跨帳戶許可授予的 CLI 範例

   ```
   aws lakeformation grant-permissions \
   --region us-east-1 \
   --cli-input-json \
   '{
       "Principal": {
           "DataLakePrincipalIdentifier": "arn:aws:iam::111122223333:role/S3TablesTestExecRole"
       },
       "Resource": {
           "Table": {
               "CatalogId": "011426214932:s3tablescatalog/chmni-s3-table-bucket-011426214932",
               "DatabaseName": "s3_table_ns",
               "Name": "test_s3_iceberg_table"
           }
       },
       "Permissions": [
           "ALL"
       ]
   }'
   ```

1.  在資源連結上授予 Lake Formation `DESCRIBE`許可。

    授予資源連結描述許可的 CLI 範例。

   ```
   aws lakeformation grant-permissions \
       --principal DataLakePrincipalIdentifier=arn:aws:iam::111122223333:role/S3TablesTestExecRole
       --resource Database='{CatalogId=111122223333;, Name=s3table_resourcelink}' \
       --permissions DESCRIBE
   ```