

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

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

# Redshift Spectrum 和 AWS Lake Formation
<a name="spectrum-lake-formation"></a>

本主題說明如何使用 Redshift Spectrum 搭配 Lake Formation。Lake Formation 是一項共用分析資料的服務。

您可以使用 AWS Lake Formation 集中定義和強制執行 Amazon S3 中所存放資料的資料庫、資料表和資料欄層級存取政策。透過啟用 Lake Formation 的 AWS Glue Data Catalog 註冊資料後，您即可使用 Redshift Spectrum 等數種服務來查詢該資料。

Lake Formation 提供資料目錄的安全功能和管理能力。在 Lake Formation 中，您能夠授予和撤銷資料庫、資料表、欄和基礎 Amazon S3 儲存體等資料目錄物件的許可。

**重要**  
在提供 Lake Formation 的 AWS 區域中，您只能使用 Redshift Spectrum 搭配已啟用 Lake Formation 的資料目錄。如需可用區域的清單，請參閱*AWS 一般參考*中的[AWS Lake Formation 端點和配額](https://docs.aws.amazon.com/general/latest/gr/lake-formation.html)。

透過使用 Redshift Spectrum 搭配 Lake Formation，您可以執行以下操作：
+ 使用 Lake Formation 做為集中位置，您可以在其中授予和撤銷對資料湖中所有資料的許可和存取控制許可。Lake Formation 提供許可階層，用以控制對資料目錄中資料庫和資料表的存取權。如需詳細資訊，請參閱《AWS Lake Formation 開發人員指南》**中的 [Lake Formation 許可概觀](https://docs.aws.amazon.com/lake-formation/latest/dg/lake-formation-permissions.html)。
+ 建立外部資料表並在資料湖中的資料上執行查詢 資料湖帳戶管理員必須先向 Lake Formation 註冊包含來源資料的現有 Amazon S3 路徑，帳戶中的使用者才可以執行查詢。管理員還需建立資料表，並授予使用者相關許可。您可授予資料庫、資料表或資料欄層級的存取權限。管理員可以使用 Lake Formation 中的資料篩選條件，對儲存在 Amazon S3 中的敏感資料授予精細的存取控制。如需詳細資訊，請參閱[使用資料篩選條件來實現列層級和儲存格層級安全](#spectrum-lake-formation-data-filters)。

  在資料目錄中註冊資料之後，每當使用者嘗試執行查詢時，Lake Formation 都會驗證該特定主體對資料表的存取權。Lake Formation 會將暫臨時憑證提供給 Redshift Spectrum，並執行查詢。
+ 針對 AWS Glue Data Catalog 使用 `GetCredentials`或 取得的 IAM 登入資料自動掛載的 執行 Redshift Spectrum 查詢`GetClusterCredentials`，並依資料庫使用者 (IAMR：username 或 IAM：username) 管理 Lake Formation 許可。

當您將 Redshift Spectrum 搭配為 Lake Formation 啟用的資料目錄一起使用時，必須具備以下其中一項：
+ 與具有資料目錄許可的叢集關聯的 IAM 角色。
+ 設定用來管理外部資源存取權的聯合 IAM 身分。如需詳細資訊，請參閱[使用聯合身分來管理 Amazon Redshift 對本機資源的存取和 Amazon Redshift 外部資料表的存取](https://docs.aws.amazon.com/redshift/latest/mgmt/authorization-fas-spectrum.html)。

**重要**  
將 Redshift Spectrum 搭配為 Lake Formation 啟用的資料目錄一起使用時，您無法鏈結 IAM 角色。

若要進一步了解設定 AWS Lake Formation 以搭配 Redshift Spectrum 使用 所需的步驟，請參閱《 *AWS Lake Formation 開發人員指南*》中的[教學課程：從 Lake Formation 中的 JDBC 來源建立資料湖](https://docs.aws.amazon.com/lake-formation/latest/dg/getting-started-tutorial-jdbc.html)。具體而言，請參閱[使用 Amazon Redshift Spectrum 查詢資料湖中的資料](https://docs.aws.amazon.com/lake-formation/latest/dg/tut-query-redshift.html)，以了解與 Redshift Spectrum 整合的詳細資訊。本主題中使用的資料 AWS 和資源取決於教學課程中的先前步驟。

## 使用資料篩選條件來實現列層級和儲存格層級安全
<a name="spectrum-lake-formation-data-filters"></a>

您可以在 中定義資料篩選條件 AWS Lake Formation ，以控制 Redshift Spectrum 查詢的資料列層級和儲存格層級存取資料目錄中定義的資料。若要進行此設定，您需要執行以下任務：
+ 使用以下資訊在 Lake Formation 中建立資料篩選條件：
  + 欄規格，內含要包含在查詢結果中或從查詢結果中排除的欄清單。
  + 列篩選運算式，指定要包含在查詢結果中的列。

  如需如何建立資料篩選條件的相關資訊，請參閱《AWS Lake Formation 開發人員指南》**中的 [Lake Formation 中的資料篩選條件](https://docs.aws.amazon.com/lake-formation/latest/dg/data-filters-about.html)。
+ 在 Amazon Redshift 中建立外部資料表，該資料表會參考已啟用 Lake Formation 的資料目錄中的資料表。如需如何使用 Redshift Spectrum 查詢 Lake Formation 資料表的詳細資訊，請參閱《AWS Lake Formation 開發人員指南》**中的[使用 Amazon Redshift Spectrum 查詢資料湖中的資料](https://docs.aws.amazon.com/lake-formation/latest/dg/tut-query-redshift.html)。

在 Amazon Redshift 中定義資料表之後，您可以查詢 Lake Formation 資料表，以及存取僅限資料篩選條件允許的列和欄。

如需如何在 Lake Formation 中設定列層級和儲存格層級安全，然後使用 Redshift Spectrum 進行查詢的詳細指南，請參閱[使用 Amazon Redshift Spectrum 搭配 AWS Lake Formation中定義的列層級和儲存格層級安全政策](https://aws.amazon.com/blogs/big-data/use-amazon-redshift-spectrum-with-row-level-and-cell-level-security-policies-defined-in-aws-lake-formation/)。