設定爬蟲程式以使用 Lake Formation 登入資料 - AWS Glue

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

設定爬蟲程式以使用 Lake Formation 登入資料

您可以設定爬蟲程式使用 AWS Lake Formation 登入資料來存取 Amazon S3 資料存放區,或具有相同 AWS 帳戶 或另一個 中基礎 Amazon S3 位置的資料目錄資料表 AWS 帳戶。如果爬蟲程式和資料型錄資料表位於同一帳戶中,您可以將現有的資料型錄資料表設定為爬蟲程式的目標。目前,使用 Data Catalog 資料表做為爬蟲程式的目標時,只允許具有單一目錄資料表的單一目錄目標。

注意

將資料型錄資料表定義為爬蟲程式目標時,請確定資料型錄資料表的基礎位置是 Amazon S3 位置。使用 Lake Formation 憑證的爬蟲程式僅支援具有基礎 Amazon S3 位置的資料型錄目標。

當爬蟲程式和已註冊的 Amazon S3 位置或資料型錄資料表位於同一帳戶 (帳戶內網路爬取) 時,需要進行設定

若要允許爬蟲程式使用 Lake Formation 憑證存取資料存放區或資料型錄資料表,您需要向 Lake Formation 註冊資料位置。此外,爬蟲程式的 IAM 角色必須具備從 Amazon S3 儲存貯體註冊所在的目的地讀取資料的許可。

您可以使用 AWS Management Console 或 AWS Command Line Interface () 完成下列組態步驟AWS CLI。

AWS Management Console
  1. 在設定爬蟲程式以存取爬蟲程式來源之前,請先向 Lake Formation 註冊資料存放區或資料型錄的資料位置。在 Lake Formation 主控台 (https://console.aws.amazon.com/lakeformation/) 中,將 Amazon S3 位置註冊為定義爬蟲程式之 中資料湖 AWS 帳戶 的根位置。如需詳細資訊,請參閱 Registering an Amazon S3 location (註冊 Amazon S3 位置)。

  2. 向用於爬蟲程式執行的 IAM 角色授與 Data location (資料位置) 許可,以便爬蟲程式可以從 Lake Formation 中的目的地讀取資料。如需詳細資訊,請參閱 Granting data location permissions (same account) (授與資料位置許可 (相同帳戶))。

  3. 將爬蟲程式角色存取許可 (Create) 授與指定作為輸出資料庫的資料庫。如需詳細資訊,請參閱 Granting database permissions using the Lake Formation console and the named resource method (使用 Lake Formation 主控台和具名資源方法授與資料庫許可)。

  4. 在 IAM 主控台 (https://console.aws.amazon.com/iam/) 中,建立爬蟲程式的 IAM 角色。將 lakeformation:GetDataAccess 政策新增至該角色。

  5. 在 AWS Glue 主控台 (https://console.aws.amazon.com/glue/) 中,在設定爬蟲程式時,選取使用 Lake Formation 登入資料來爬蟲 Amazon S3 資料來源的選項。

    注意

    accountId 欄位對於帳戶內網路爬取而言是選填的。

AWS CLI
aws glue --profile demo create-crawler --debug --cli-input-json '{ "Name": "prod-test-crawler", "Role": "arn:aws:iam::111122223333:role/service-role/AWSGlueServiceRole-prod-test-run-role", "DatabaseName": "prod-run-db", "Description": "", "Targets": { "S3Targets":[ { "Path": "s3://crawl-testbucket" } ] }, "SchemaChangePolicy": { "UpdateBehavior": "LOG", "DeleteBehavior": "LOG" }, "RecrawlPolicy": { "RecrawlBehavior": "CRAWL_EVERYTHING" }, "LineageConfiguration": { "CrawlerLineageSettings": "DISABLE" }, "LakeFormationConfiguration": { "UseLakeFormationCredentials": true, "AccountId": "111122223333" }, "Configuration": { "Version": 1.0, "CrawlerOutput": { "Partitions": { "AddOrUpdateBehavior": "InheritFromTable" }, "Tables": {"AddOrUpdateBehavior": "MergeNewColumns" } }, "Grouping": { "TableGroupingPolicy": "CombineCompatibleSchemas" } }, "CrawlerSecurityConfiguration": "", "Tags": { "KeyName": "" } }'