

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

# 使用 Lake Formation for Amazon EMR Spark 的 S3 路徑型存取
<a name="lake-formation-path-based-credential-vending"></a>

透過 Amazon EMR 7.13.0 版和更新版本，您可以使用 [AWS Lake Formation Access Grants 外掛程式](https://docs.aws.amazon.com/lake-formation/latest/dg/accessing-s3-locations.html)來取得向 Lake Formation 註冊的 S3 路徑的臨時憑證。這可讓直接參考 S3 路徑的 Spark 查詢使用 Lake Formation 提供的登入資料，以及 Full Table Access (FTA) 提供的現有資料表名稱型登入資料販賣。

Lake Formation Access Grants 外掛程式與 Spark 中的 S3A 檔案系統整合。啟用時，S3A 會使用外掛程式來呼叫 Lake Formation [GetTemporaryDataLocationCredentials](https://docs.aws.amazon.com/lake-formation/latest/APIReference/API_GetTemporaryDataLocationCredentials.html) API，以取得屬於 Lake Formation 註冊資料表之 S3 路徑的臨時憑證。

當您的 Spark 任務透過直接參考 S3 路徑 （例如 `spark.read.parquet("s3a://my-bucket/my-table/")`) 而不是使用資料表名稱來讀取或寫入資料時，此外掛程式非常有用。當 Lake Formation 存取遭拒時， 外掛程式也支援 S3 存取授權或 IAM 角色憑證的選用後援。

## 與完整資料表存取 (FTA) 的關係
<a name="lake-formation-path-based-relationship-fta"></a>

現有的完整資料表存取功能使用 [GetTemporaryGlueTableCredentials](https://docs.aws.amazon.com/lake-formation/latest/APIReference/API_GetTemporaryGlueTableCredentials.html) API，可根據資料表名稱提供登入資料。Lake Formation Access Grants 外掛程式使用 [GetTemporaryDataLocationCredentials](https://docs.aws.amazon.com/lake-formation/latest/APIReference/API_GetTemporaryDataLocationCredentials.html) API，根據 S3 路徑提供登入資料。

您可以同時使用這兩個功能。當兩者都啟用時，FTA 登入資料優先於資料表名稱查詢，而外掛程式會處理直接 S3 路徑查詢。

## 先決條件
<a name="lake-formation-path-based-prerequisites"></a>

在使用 Lake Formation Access Grants 外掛程式之前，請完成下列步驟：
+ 為您的 Amazon EMR 環境設定完整資料表存取 (FTA)。如需說明，請參閱。
+ 在 Lake Formation 主控台中，向擁有者帳戶註冊 S3 路徑：

  1. 導覽至**資料湖位置**。

  1. 選取位置並啟用**向擁有者帳戶註冊 S3 路徑**。
+ 在資料表上授予執行時間角色適當的 Lake Formation 許可：
  + 若要讀取資料表資料，請在資料表上授予執行期角色完整`SELECT`許可。
  + 若要修改資料表資料，請在資料表上授予執行時間角色`SUPER`許可。

## 啟用 Lake Formation Access Grants 外掛程式
<a name="lake-formation-path-based-enable"></a>

若要啟用外掛程式，請在 Spark 工作階段中設定下列 S3A 組態屬性：


**Lake Formation Access Grants 外掛程式組態屬性**  

| 屬性 | 預設 | 說明 | 
| --- | --- | --- | 
| fs.s3a.lakeformation.access.grants.enabled | FALSE | 啟用 Lake Formation Access Grants 外掛程式。 | 
| fs.s3a.lakeformation.access.grants.fallback.to.iam | FALSE | 如果 Lake Formation 拒絕存取，則啟用 S3 存取授權或 IAM 角色憑證的後援。 | 

## 備用行為
<a name="lake-formation-path-based-fallback"></a>

當 `fs.s3a.lakeformation.access.grants.fallback.to.iam` 設定為 時`true`，如果 Lake Formation 拒絕存取，外掛程式會使用備用鏈。這適用於某些 S3 路徑已向 Lake Formation 註冊，而其他則透過 S3 Access Grants 或 IAM 政策管理的情況。

啟用後援時，外掛程式會嘗試依下列順序取得登入資料：

1. **Lake Formation** – 外掛程式會呼叫 [GetTemporaryDataLocationCredentials](https://docs.aws.amazon.com/lake-formation/latest/APIReference/API_GetTemporaryDataLocationCredentials.html)。如果 Lake Formation 授予存取權，外掛程式會傳回這些登入資料。

1. **S3 存取授權** – 如果 Lake Formation 拒絕存取，外掛程式會檢查 S3 存取授權是否可以為請求的路徑提供登入資料。如果 S3 Access Grants 執行個體涵蓋路徑，且發起人具有相符的授權，則外掛程式會使用這些登入資料。

1. **IAM 角色** – 如果 Lake Formation 和 S3 Access Grants 都拒絕存取，外掛程式會回到連接至任務的 IAM 角色登入資料。

## 考量和限制
<a name="lake-formation-path-based-considerations"></a>
+ 外掛程式支援 Apache Hive、Apache Hudi 和 Delta Lake 資料表格式。目前不支援 Apache Iceberg。
+ Amazon EMR Spark 精細存取控制 (FGAC) 模式目前不支援此外掛程式。
+ 路徑型登入資料販賣需要在 Glue Data Catalog 中的資料表及其 S3 位置之間進行 1：1 AWS 映射。