使用 Lake Formation 示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Lake Formation 示例 Amazon CLI

以下代码示例向您展示了如何使用 with Lake Formation 来执行操作和实现常见场景。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 add-lf-tags-to-resource

Amazon CLI

将一个或多个 LF 标签附加到现有资源

以下add-lf-tags-to-resource示例将给定的 LF-Tag 附加到表资源。

aws lakeformation add-lf-tags-to-resource \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "analyst" ] }] }

输出:

{ "Failures": [] }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的为数据目录资源分配 LF 标签

以下代码示例演示如何使用 batch-grant-permissions

Amazon CLI

向委托人批量授予资源权限

以下batch-grant-permissions示例批量向委托人授予对指定资源的访问权限。

aws lakeformation batch-grant-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Entries": [{ "Id": "1", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [ "ALL" ] }, { "Id": "2", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_customer" } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [ "ALL" ] }, { "Id": "3", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-business-analyst" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [ "ALL" ] }, { "Id": "4", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "DataCellsFilter": { "TableCatalogId": "123456789111", "DatabaseName": "tpc", "TableName": "dl_tpc_item", "Name": "developer_item" } }, "Permissions": [ "SELECT" ], "PermissionsWithGrantOption": [] } ] }

输出:

{ "Failures": [] }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

以下代码示例演示如何使用 batch-revoke-permissions

Amazon CLI

批量撤消委托人对资源的权限

以下batch-revoke-permissions示例批量撤消委托人对指定资源的访问权限。

aws lakeformation batch-revoke-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Entries": [{ "Id": "1", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [ "ALL" ] }, { "Id": "2", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-business-analyst" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [ "ALL" ] } ] }

输出:

{ "Failures": [] }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

以下代码示例演示如何使用 cancel-transaction

Amazon CLI

取消交易

以下cancel-transaction示例取消了交易。

aws lakeformation cancel-transaction \ --transaction-id='b014d972ca8347b89825e33c5774aec4'

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CancelTransaction中的。

以下代码示例演示如何使用 commit-transaction

Amazon CLI

提交事务

以下commit-transaction示例提交了交易。

aws lakeformation commit-transaction \ --transaction-id='b014d972ca8347b89825e33c5774aec4'

输出:

{ "TransactionStatus": "committed" }

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CommitTransaction中的。

以下代码示例演示如何使用 create-data-cells-filter

Amazon CLI

示例 1:创建数据单元格筛选器

以下create-data-cells-filter示例创建了一个数据单元格筛选器,允许用户根据行条件授予对某些列的访问权限。

aws lakeformation create-data-cells-filter \ --cli-input-json file://input.json

input.json 的内容:

{ "TableData": { "ColumnNames": ["p_channel_details", "p_start_date_sk", "p_promo_name"], "DatabaseName": "tpc", "Name": "developer_promotion", "RowFilter": { "FilterExpression": "p_promo_name='ese'" }, "TableCatalogId": "123456789111", "TableName": "dl_tpc_promotion" } }

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formation 开发者指南中的 Lake Formation 中的Amazon 数据筛选和单元级安全

示例 2:创建列筛选器

以下create-data-cells-filter示例创建了一个数据筛选器,允许用户授予对某些列的访问权限。

aws lakeformation create-data-cells-filter \ --cli-input-json file://input.json

input.json 的内容:

{ "TableData": { "ColumnNames": ["p_channel_details", "p_start_date_sk", "p_promo_name"], "DatabaseName": "tpc", "Name": "developer_promotion_allrows", "RowFilter": { "AllRowsWildcard": {} }, "TableCatalogId": "123456789111", "TableName": "dl_tpc_promotion" } }

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formation 开发者指南中的 Lake Formation 中的Amazon 数据筛选和单元级安全

示例 3:使用排除列创建数据筛选器

以下create-data-cells-filter示例创建了一个数据筛选器,允许用户授予除上述列以外的所有列的访问权限。

aws lakeformation create-data-cells-filter \ --cli-input-json file://input.json

input.json 的内容:

{ "TableData": { "ColumnWildcard": { "ExcludedColumnNames": ["p_channel_details", "p_start_date_sk"] }, "DatabaseName": "tpc", "Name": "developer_promotion_excludecolumn", "RowFilter": { "AllRowsWildcard": {} }, "TableCatalogId": "123456789111", "TableName": "dl_tpc_promotion" } }

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formation 开发者指南中的 Lake Formation 中的Amazon 数据筛选和单元级安全

以下代码示例演示如何使用 create-lf-tag

Amazon CLI

创建 LF-Tag

以下create-lf-tag示例使用指定的名称和值创建一个 LF-Tag。

aws lakeformation create-lf-tag \ --catalog-id '123456789111' \ --tag-key 'usergroup' \ --tag-values '["developer","analyst","campaign"]'

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的管理 LF 标签以实现元数据访问控制

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateLfTag中的。

以下代码示例演示如何使用 delete-data-cells-filter

Amazon CLI

删除数据单元格筛选器

以下delete-data-cells-filter示例删除给定的数据单元格筛选器。

aws lakeformation delete-data-cells-filter \ --cli-input-json file://input.json

input.json 的内容:

{ "TableCatalogId": "123456789111", "DatabaseName": "tpc", "TableName": "dl_tpc_promotion", "Name": "developer_promotion" }

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formation 开发者指南中的 Lake Formation 中的Amazon 数据筛选和单元级安全

以下代码示例演示如何使用 delete-lf-tag

Amazon CLI

删除 LF-tag 定义

以下delete-lf-tag示例删除了 LF-Tag 的定义。

aws lakeformation delete-lf-tag \ --catalog-id '123456789111' \ --tag-key 'usergroup'

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的管理 LF 标签以实现元数据访问控制

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteLfTag中的。

以下代码示例演示如何使用 delete-objects-on-cancel

Amazon CLI

取消交易时删除对象

以下delete-objects-on-cancel示例在取消事务时删除列出的 s3 对象。

aws lakeformation delete-objects-on-cancel \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "012345678901", "DatabaseName": "tpc", "TableName": "dl_tpc_household_demographics_gov", "TransactionId": "1234d972ca8347b89825e33c5774aec4", "Objects": [{ "Uri": "s3://lf-data-lake-012345678901/target/dl_tpc_household_demographics_gov/run-unnamed-1-part-block-0-r-00000-snappy-ff26b17504414fe88b302cd795eabd00.parquet", "ETag": "1234ab1fc50a316b149b4e1f21a73800" }] }

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

以下代码示例演示如何使用 deregister-resource

Amazon CLI

取消注册数据湖存储

以下deregister-resource示例将资源注销为由 Lake Formation 管理的资源。

aws lakeformation deregister-resource \ --cli-input-json file://input.json

input.json 的内容:

{ "ResourceArn": "arn:aws:s3:::lf-emr-athena-result-123" }

此命令不生成任何输出。

有关更多信息,请参阅 Lake F ormation 开发者指南中的向数据湖添加 Amazon S3 位置。Amazon

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeregisterResource中的。

以下代码示例演示如何使用 describe-transaction

Amazon CLI

检索交易详情

以下describe-transaction示例返回单笔交易的详细信息。

aws lakeformation describe-transaction \ --transaction-id='8cb4b1a7cc8d486fbaca9a64e7d9f5ce'

输出:

{ "TransactionDescription": { "TransactionId": "12345972ca8347b89825e33c5774aec4", "TransactionStatus": "committed", "TransactionStartTime": "2022-08-10T14:29:04.046000+00:00", "TransactionEndTime": "2022-08-10T14:29:09.681000+00:00" } }

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

以下代码示例演示如何使用 extend-transaction

Amazon CLI

延长交易

以下extend-transaction示例扩展了事务。

aws lakeformation extend-transaction \ --transaction-id='8cb4b1a7cc8d486fbaca9a64e7d9f5ce'

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ExtendTransaction中的。

以下代码示例演示如何使用 get-data-lake-settings

Amazon CLI

检索 Amazon Lake Formation 管理的数据湖设置

以下get-data-lake-settings示例检索数据湖管理员列表和其他数据湖设置。

aws lakeformation get-data-lake-settings \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111" }

输出:

{ "DataLakeSettings": { "DataLakeAdmins": [{ "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-admin" }], "CreateDatabaseDefaultPermissions": [], "CreateTableDefaultPermissions": [ { "Principal": { "DataLakePrincipalIdentifier": "IAM_ALLOWED_PRINCIPALS" }, "Permissions": [ "ALL" ] } ], "TrustedResourceOwners": [], "AllowExternalDataFiltering": true, "ExternalDataFilteringAllowList": [{ "DataLakePrincipalIdentifier": "123456789111" }], "AuthorizedSessionTagValueList": [ "Amazon EMR" ] } }

有关更多信息,请参阅 Lake Formati on 开发者指南中的更改数据Amazon 湖的默认安全设置

以下代码示例演示如何使用 get-effective-permissions-for-path

Amazon CLI

检索位于特定路径的资源的权限

以下get-effective-permissions-for-path示例返回位于 Amazon S3 中某个路径上的指定表或数据库资源的 Lake Formation 权限。

aws lakeformation get-effective-permissions-for-path \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "ResourceArn": "arn:aws:s3:::lf-data-lake-123456789111" }

输出:

{ "Permissions": [{ "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-campaign-manager" }, "Resource": { "Database": { "Name": "tpc" } }, "Permissions": [ "DESCRIBE" ], "PermissionsWithGrantOption": [] }, { "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:role/EMR-RuntimeRole" }, "Resource": { "Database": { "Name": "tpc" } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [] }, { "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:saml-provider/oktaSAMLProvider:user/emr-developer" }, "Resource": { "Database": { "Name": "tpc" } }, "Permissions": [ "ALL", "DESCRIBE" ], "PermissionsWithGrantOption": [] }, { "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-admin" }, "Resource": { "Database": { "Name": "tpc" } }, "Permissions": [ "ALL", "ALTER", "CREATE_TABLE", "DESCRIBE", "DROP" ], "PermissionsWithGrantOption": [ "ALL", "ALTER", "CREATE_TABLE", "DESCRIBE", "DROP" ] }, { "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:role/LF-GlueServiceRole" }, "Resource": { "Database": { "Name": "tpc" } }, "Permissions": [ "CREATE_TABLE" ], "PermissionsWithGrantOption": [] } ], "NextToken": "E5SlJDSTZleUp6SWpvaU9UQTNORE0zTXpFeE5Ua3pJbjE5TENKbGVIQnBjbUYwYVc5dUlqcDdJbk5sWTI5dVpITWlPakUyTm==" }

有关更多信息,请参阅 Lake Formation 开发者指南中的管理Amazon Lake Formation 权限

以下代码示例演示如何使用 get-lf-tag

Amazon CLI

检索 LF-Tag 的定义

以下get-lf-tag示例检索 LF-Tag 的定义。

aws lakeformation get-lf-tag \ --catalog-id '123456789111' \ --tag-key 'usergroup'

输出:

{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "analyst", "campaign", "developer" ] }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的管理 LF 标签以实现元数据访问控制

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetLfTag中的。

以下代码示例演示如何使用 get-query-state

Amazon CLI

检索已提交查询的状态

以下get-query-state示例返回先前提交的查询的状态。

aws lakeformation get-query-state \ --query-id='1234273f-4a62-4cda-8d98-69615ee8be9b'

输出:

{ "State": "FINISHED" }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的事务数据操作

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetQueryState中的。

以下代码示例演示如何使用 get-query-statistics

Amazon CLI

检索查询统计信息

以下get-query-statistics示例检索有关查询计划和执行的统计信息。

aws lakeformation get-query-statistics \ --query-id='1234273f-4a62-4cda-8d98-69615ee8be9b'

输出:

{ "ExecutionStatistics": { "AverageExecutionTimeMillis": 0, "DataScannedBytes": 0, "WorkUnitsExecutedCount": 0 }, "PlanningStatistics": { "EstimatedDataToScanBytes": 43235, "PlanningTimeMillis": 2377, "QueueTimeMillis": 440, "WorkUnitsGeneratedCount": 1 }, "QuerySubmissionTime": "2022-08-11T02:14:38.641870+00:00" }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的事务数据操作

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetQueryStatistics中的。

以下代码示例演示如何使用 get-resource-lf-tags

Amazon CLI

列出 LF 标签

以下list-lf-tags示例返回请求者有权查看的 LF-Tag 列表。

aws lakeformation list-lf-tags \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "ResourceShareType": "ALL", "MaxResults": 2 }

输出:

{ "LFTags": [{ "CatalogId": "123456789111", "TagKey": "category", "TagValues": [ "private", "public" ] }, { "CatalogId": "123456789111", "TagKey": "group", "TagValues": [ "analyst", "campaign", "developer" ] }], "NextToken": "kIiwiZXhwaXJhdGlvbiI6eyJzZWNvbmRzIjoxNjYwMDY4dCI6ZmFsc2V9" }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的管理 LF 标签以实现元数据访问控制

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetResourceLfTags中的。

以下代码示例演示如何使用 get-table-objects

Amazon CLI

列出受管辖表格的对象

以下get-table-objects示例返回构成指定受管辖表的一组 Amazon S3 对象。

aws lakeformation get-table-objects \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "012345678901", "DatabaseName": "tpc", "TableName": "dl_tpc_household_demographics_gov", "QueryAsOfTime": "2022-08-10T15:00:00" }

输出:

{ "Objects": [{ "PartitionValues": [], "Objects": [{ "Uri": "s3://lf-data-lake-012345678901/target/dl_tpc_household_demographics_gov/run-unnamed-1-part-block-0-r-00000-snappy-ff26b17504414fe88b302cd795eabd00.parquet", "ETag": "12345b1fc50a316b149b4e1f21a73800", "Size": 43235 }] }] }

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetTableObjects中的。

以下代码示例演示如何使用 get-work-unit-results

Amazon CLI

检索给定查询的工作单位

以下get-work-unit-results示例返回查询结果的工作单元。

aws lakeformation get-work-units \ --query-id='1234273f-4a62-4cda-8d98-69615ee8be9b' \ --work-unit-id '0' \ --work-unit-token 'B2fMSdmQXe9umX8Ux8XCo4=' outfile

输出:

outfile with Blob content.

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的事务数据操作

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetWorkUnitResults中的。

以下代码示例演示如何使用 get-work-units

Amazon CLI

检索工作单元

以下get-work-units示例检索 StartQueryPlanning 操作生成的工作单元。

aws lakeformation get-work-units \ --query-id='1234273f-4a62-4cda-8d98-69615ee8be9b'

输出:

{ "WorkUnitRanges": [{ "WorkUnitIdMax": 0, "WorkUnitIdMin": 0, "WorkUnitToken": "1234eMAk4kLO4umqEL4Z5WuxL04AXwABABVhd3MtY3J5cHRvLXB1YmxpYy1rZXkAREEwYm9QbkhINmFYTWphbmMxZW1PQmEyMGlUb0JFbXNlWmRYc0NmckRIR1dmQ0hjY2YzNFdMcmNXb2JGZmhEK0QvZz09AAEAB2F3cy1rbXMAS2Fybjphd3M6a21zOnVzLWVhc3QtMTo3MDkxNTAyNDkyNDk6a2V5L2VmYmI3NDUyLTY1MjYtNGJiOS1iNmZhLTEzYzJkMTM3MmU2OQC4AQIBAHg6eWNF2ZrQATTAuPDJVCEAQSyIF67vX+f88jzGrYq22gE6jkQlpOB+Oet2eqNUmFudAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMCOEWRdafowek3RUmAgEQgDsYZZE84nnnbNmvsqCBPLh19nLQ10mUWOg9IfiaOwefEn6L920V0x1LpJACo7MtIBLXnbGcz2dFDZjFygIAAAAADAAAEAAAAAAAAAAAAAAAAAAQSQf8XDSI5pvR4Fx4JsrS/////wAAAAEAAAAAAAAAAAAAAAEAAACX3/w5h75QAPomfKH+cyEKYU1yccUmBl+VSojiGOtdsUk7vcjYXUUboYm3dvqRqX2s4gROMOn+Ij8R0/8jYmnHkpvyAFNVRPyETyIKg7k5Z9+5I1c2d3446Jw/moWGGxjH8AEG9h27ytmOhozxDOEi/F2ZoXz6wlGDfGUo/2WxCkYOhTyNaw6TM+7drTM7yrW4iNVLUM0LX0xnFjIAhLhooWJek6vjQZUAZzBlAjBH8okRtYP8R7AY2Wls/hqFBhG0V4l42AC0LxsuZbMQrE2SzWZUZ0E9Uew7/n0cyX4CMQDR79INyv4ysMByW9kKGGKyba+cCNklExMR+btBQBmMuB2fMSdmQXe9umX8Ux8XCo4=" }], "QueryId": "1234273f-4a62-4cda-8d98-69615ee8be9b" }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的事务数据操作

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetWorkUnits中的。

以下代码示例演示如何使用 grant-permissions

Amazon CLI

示例 1:使用 LF-tags 向委托人授予对资源的权限

以下grant-permissions示例向委托人授予与 LF-Tag 策略匹配的数据库资源的所有权限。

aws lakeformation grant-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-admin" }, "Resource": { "LFTagPolicy": { "CatalogId": "123456789111", "ResourceType": "DATABASE", "Expression": [{ "TagKey": "usergroup", "TagValues": [ "analyst", "developer" ] }] } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [ "ALL" ] }

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

示例 2:向委托人授予列级权限

以下grant-permissions示例向委托人授予选择特定列的权限。

aws lakeformation grant-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "TableWithColumns": { "CatalogId": "123456789111", "ColumnNames": ["p_end_date_sk"], "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "Permissions": [ "SELECT" ], "PermissionsWithGrantOption": [] }

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

示例 3:向委托人授予表权限

以下grant-permissions示例向委托人授予对给定数据库中所有表的选择权限。

aws lakeformation grant-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "TableWildcard": {} } }, "Permissions": [ "SELECT" ], "PermissionsWithGrantOption": [] }

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

示例 4:向委托人授予 LF 标签的权限

以下grant-permissions示例向委托人授予对 LF-Tags 的关联权限。

aws lakeformation grant-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "LFTag": { "CatalogId": "123456789111", "TagKey": "category", "TagValues": [ "private", "public" ] } }, "Permissions": [ "ASSOCIATE" ], "PermissionsWithGrantOption": [] }

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

示例 5:向委托人授予数据位置权限

以下grant-permissions示例向委托人授予数据定位权限。

aws lakeformation grant-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "DataLocation": { "CatalogId": "123456789111", "ResourceArn": "arn:aws:s3:::lf-data-lake-123456789111" } }, "Permissions": [ "DATA_LOCATION_ACCESS" ], "PermissionsWithGrantOption": [] }

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GrantPermissions中的。

以下代码示例演示如何使用 list-data-cells-filter

Amazon CLI

列出数据单元格筛选器

以下list-data-cells-filter示例列出了给定表的数据单元格筛选器。

aws lakeformation list-data-cells-filter \ --cli-input-json file://input.json

input.json 的内容:

{ "MaxResults": 2, "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }

输出:

{ "DataCellsFilters": [{ "TableCatalogId": "123456789111", "DatabaseName": "tpc", "TableName": "dl_tpc_promotion", "Name": "developer_promotion", "RowFilter": { "FilterExpression": "p_promo_name='ese'" }, "ColumnNames": [ "p_channel_details", "p_start_date_sk", "p_purpose", "p_promo_id", "p_promo_name", "p_end_date_sk", "p_discount_active" ] }, { "TableCatalogId": "123456789111", "DatabaseName": "tpc", "TableName": "dl_tpc_promotion", "Name": "developer_promotion_allrows", "RowFilter": { "FilterExpression": "TRUE", "AllRowsWildcard": {} }, "ColumnNames": [ "p_channel_details", "p_start_date_sk", "p_promo_name" ] } ], "NextToken": "2MDA2MTgwNiwibmFub3MiOjE0MDAwMDAwMH19" }

有关更多信息,请参阅 Lake Formation 开发者指南中的 Lake Formation 中的Amazon 数据筛选和单元级安全

以下代码示例演示如何使用 list-permissions

Amazon CLI

示例 1:检索资源的主体权限列表

以下list-permissions示例返回数据库资源的主体权限列表。

aws lakeformation list-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "ResourceType": "DATABASE", "MaxResults": 2 }

输出:

{ "PrincipalResourcePermissions": [{ "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-campaign-manager" }, "Resource": { "Database": { "CatalogId": "123456789111", "Name": "tpc" } }, "Permissions": [ "DESCRIBE" ], "PermissionsWithGrantOption": [] }], "NextToken": "E5SlJDSTZleUp6SWpvaU9UQTNORE0zTXpFeE5Ua3pJbjE5TENKbGVIQnBjbUYwYVc5dUlqcDdJbk5sWTI5dVpITWlPakUyTm" }

有关更多信息,请参阅 Lake Formation 开发者指南中的管理Amazon Lake Formation 权限

示例 2:使用数据筛选器检索表的主体权限列表

以下list-permissions示例列出了向委托人授予的带有相关数据筛选器的表的权限。

aws lakeformation list-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_customer" } }, "IncludeRelated": "TRUE", "MaxResults": 10 }

输出:

{ "PrincipalResourcePermissions": [{ "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:role/Admin" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "customer", "Name": "customer_invoice" } }, "Permissions": [ "ALL", "ALTER", "DELETE", "DESCRIBE", "DROP", "INSERT" ], "PermissionsWithGrantOption": [ "ALL", "ALTER", "DELETE", "DESCRIBE", "DROP", "INSERT" ] }, { "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:role/Admin" }, "Resource": { "TableWithColumns": { "CatalogId": "123456789111", "DatabaseName": "customer", "Name": "customer_invoice", "ColumnWildcard": {} } }, "Permissions": [ "SELECT" ], "PermissionsWithGrantOption": [ "SELECT" ] }, { "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:role/Admin" }, "Resource": { "DataCellsFilter": { "TableCatalogId": "123456789111", "DatabaseName": "customer", "TableName": "customer_invoice", "Name": "dl_us_customer" } }, "Permissions": [ "DESCRIBE", "SELECT", "DROP" ], "PermissionsWithGrantOption": [] } ], "NextToken": "VyeUFjY291bnRQZXJtaXNzaW9ucyI6ZmFsc2V9" }

有关更多信息,请参阅 Lake Formation 开发者指南中的管理Amazon Lake Formation 权限

示例 3:检索 LF 标签的主体权限列表

以下list-permissions示例列出了授予委托人的对 LF 标签的权限。

aws lakeformation list-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Resource": { "LFTag": { "CatalogId": "123456789111", "TagKey": "category", "TagValues": [ "private" ] } }, "MaxResults": 10 }

输出:

{ "PrincipalResourcePermissions": [{ "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-admin" }, "Resource": { "LFTag": { "CatalogId": "123456789111", "TagKey": "category", "TagValues": [ "*" ] } }, "Permissions": [ "DESCRIBE" ], "PermissionsWithGrantOption": [ "DESCRIBE" ] }, { "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-admin" }, "Resource": { "LFTag": { "CatalogId": "123456789111", "TagKey": "category", "TagValues": [ "*" ] } }, "Permissions": [ "ASSOCIATE" ], "PermissionsWithGrantOption": [ "ASSOCIATE" ] } ], "NextToken": "EJwY21GMGFXOXVJanA3SW5Ocm1pc3Npb25zIjpmYWxzZX0=" }

有关更多信息,请参阅 Lake Formation 开发者指南中的管理Amazon Lake Formation 权限

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListPermissions中的。

以下代码示例演示如何使用 list-resources

Amazon CLI

列出 Lake Formation 管理的资源

以下list-resources示例列出了与 Lake Formation 管理的条件相匹配的资源。

aws lakeformation list-resources \ --cli-input-json file://input.json

input.json 的内容:

{ "FilterConditionList": [{ "Field": "ROLE_ARN", "ComparisonOperator": "CONTAINS", "StringValueList": [ "123456789111" ] }], "MaxResults": 10 }

输出:

{ "ResourceInfoList": [{ "ResourceArn": "arn:aws:s3:::lf-data-lake-123456789111", "RoleArn": "arn:aws:iam::123456789111:role/LF-GlueServiceRole", "LastModified": "2022-07-21T02:12:46.669000+00:00" }, { "ResourceArn": "arn:aws:s3:::lf-emr-test-123456789111", "RoleArn": "arn:aws:iam::123456789111:role/EMRLFS3Role", "LastModified": "2022-07-29T16:22:03.211000+00:00" } ] }

有关更多信息,请参阅 Lake Formation 开发者指南中的管理Amazon Lake Formation 权限

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListResources中的。

以下代码示例演示如何使用 list-transactions

Amazon CLI

列出所有交易详情

以下list-transactions示例返回有关交易及其状态的元数据。

aws lakeformation list-transactions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "StatusFilter": "ALL", "MaxResults": 3 }

输出:

{ "Transactions": [{ "TransactionId": "1234569f08804cb790d950d4d0fe485e", "TransactionStatus": "committed", "TransactionStartTime": "2022-08-10T14:32:29.220000+00:00", "TransactionEndTime": "2022-08-10T14:32:33.751000+00:00" }, { "TransactionId": "12345972ca8347b89825e33c5774aec4", "TransactionStatus": "committed", "TransactionStartTime": "2022-08-10T14:29:04.046000+00:00", "TransactionEndTime": "2022-08-10T14:29:09.681000+00:00" }, { "TransactionId": "12345daf6cb047dbba8ad9b0414613b2", "TransactionStatus": "committed", "TransactionStartTime": "2022-08-10T13:56:51.261000+00:00", "TransactionEndTime": "2022-08-10T13:56:51.547000+00:00" } ], "NextToken": "77X1ebypsI7os+X2lhHsZLGNCDK3nNGpwRdFpicSOHgcX1/QMoniUAKcpR3kj3ts3PVdMA==" }

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListTransactions中的。

以下代码示例演示如何使用 put-data-lake-settings

Amazon CLI

设置 Amazon Lake Formation 管理的数据湖设置

以下put-data-lake-settings示例设置了数据湖管理员列表和其他数据湖设置。

aws lakeformation put-data-lake-settings \ --cli-input-json file://input.json

input.json 的内容:

{ "DataLakeSettings": { "DataLakeAdmins": [{ "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-admin" } ], "CreateDatabaseDefaultPermissions": [], "CreateTableDefaultPermissions": [], "TrustedResourceOwners": [], "AllowExternalDataFiltering": true, "ExternalDataFilteringAllowList": [{ "DataLakePrincipalIdentifier ": "123456789111" }], "AuthorizedSessionTagValueList": ["Amazon EMR"] } }

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formati on 开发者指南中的更改数据Amazon 湖的默认安全设置

以下代码示例演示如何使用 register-resource

Amazon CLI

示例 1:使用服务关联角色注册数据湖存储

以下register-resource示例使用服务关联角色将资源注册为由 Lake Formation 管理。

aws lakeformation register-resource \ --cli-input-json file://input.json

input.json 的内容:

{ "ResourceArn": "arn:aws:s3:::lf-emr-athena-result-123", "UseServiceLinkedRole": true }

此命令不生成任何输出。

有关更多信息,请参阅 Lake F ormation 开发者指南中的向数据湖添加 Amazon S3 位置。Amazon

示例 2:使用自定义角色注册数据湖存储

以下register-resource示例使用自定义角色将资源注册为由 Lake Formation 管理的资源。

aws lakeformation register-resource \ --cli-input-json file://input.json

input.json 的内容:

{ "ResourceArn": "arn:aws:s3:::lf-emr-athena-result-123", "UseServiceLinkedRole": false, "RoleArn": "arn:aws:iam::123456789111:role/LF-GlueServiceRole" }

此命令不生成任何输出。

有关更多信息,请参阅 Lake F ormation 开发者指南中的向数据湖添加 Amazon S3 位置。Amazon

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考RegisterResource中的。

以下代码示例演示如何使用 remove-lf-tags-from-resource

Amazon CLI

从资源中删除 LF-Tag

以下remove-lf-tags-from-resource示例删除了与表资源的 LF-Tag 关联。

aws lakeformation remove-lf-tags-from-resource \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }

输出:

{ "Failures": [] }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的为数据目录资源分配 LF 标签

以下代码示例演示如何使用 revoke-permissions

Amazon CLI

撤消委托人对资源的权限

以下revoke-permissions示例撤消对给定数据库特定表的主体访问权限。

aws lakeformation revoke-permissions \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "123456789111", "Principal": { "DataLakePrincipalIdentifier": "arn:aws:iam::123456789111:user/lf-developer" }, "Resource": { "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_promotion" } }, "Permissions": [ "ALL" ], "PermissionsWithGrantOption": [] }

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的授予和撤消数据目录资源的权限

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考RevokePermissions中的。

以下代码示例演示如何使用 search-databases-by-lf-tags

Amazon CLI

通过 LFTags 搜索数据库资源

以下search-databases-by-lf-tags示例搜索与 LFTag 表达式匹配的数据库资源。

aws lakeformation search-databases-by-lf-tags \ --cli-input-json file://input.json

input.json 的内容:

{ "MaxResults": 1, "CatalogId": "123456789111", "Expression": [{ "TagKey": "usergroup", "TagValues": [ "developer" ] }] }

输出:

{ "DatabaseList": [{ "Database": { "CatalogId": "123456789111", "Name": "tpc" }, "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }] }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的查看 LF-Tag 分配给的资源

以下代码示例演示如何使用 search-tables-by-lf-tags

Amazon CLI

按 LFTags 搜索表格资源

以下search-tables-by-lf-tags示例搜索与 LFTag 表达式匹配的表资源。

aws lakeformation search-tables-by-lf-tags \ --cli-input-json file://input.json

input.json 的内容:

{ "MaxResults": 2, "CatalogId": "123456789111", "Expression": [{ "TagKey": "usergroup", "TagValues": [ "developer" ] }] }

输出:

{ "NextToken": "c2VhcmNoQWxsVGFnc0luVGFibGVzIjpmYWxzZX0=", "TableList": [{ "Table": { "CatalogId": "123456789111", "DatabaseName": "tpc", "Name": "dl_tpc_item" }, "LFTagOnDatabase": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }], "LFTagsOnTable": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }], "LFTagsOnColumns": [{ "Name": "i_item_desc", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_container", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_wholesale_cost", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_manufact_id", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_brand_id", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_formulation", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_current_price", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_size", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_rec_start_date", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_manufact", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_item_sk", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_manager_id", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_item_id", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_class_id", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_class", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_category", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_category_id", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_brand", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_units", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_rec_end_date", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_color", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] }, { "Name": "i_product_name", "LFTags": [{ "CatalogId": "123456789111", "TagKey": "usergroup", "TagValues": [ "developer" ] }] } ] }] }

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的查看 LF-Tag 分配给的资源

以下代码示例演示如何使用 start-query-planning

Amazon CLI

处理查询语句

以下start-query-planning示例提交了处理查询语句的请求。

aws lakeformation start-query-planning \ --cli-input-json file://input.json

input.json 的内容:

{ "QueryPlanningContext": { "CatalogId": "012345678901", "DatabaseName": "tpc" }, "QueryString": "select * from dl_tpc_household_demographics_gov where hd_income_band_sk=9" }

输出:

{ "QueryId": "772a273f-4a62-4cda-8d98-69615ee8be9b" }

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考StartQueryPlanning中的。

以下代码示例演示如何使用 start-transaction

Amazon CLI

开始新交易

以下start-transaction示例启动一个新事务并返回其交易 ID。

aws lakeformation start-transaction \ --transaction-type = 'READ_AND_WRITE'

输出:

{ "TransactionId": "b014d972ca8347b89825e33c5774aec4" }

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考StartTransaction中的。

以下代码示例演示如何使用 update-lf-tag

Amazon CLI

更新 LF-tag 的定义

以下update-lf-tag示例更新了 LF-tag 的定义。

aws lakeformation update-lf-tag \ --catalog-id '123456789111' \ --tag-key 'usergroup' \ --tag-values-to-add '["admin"]'

此命令不生成任何输出。

有关更多信息,请参阅 La Amazon ke Formation 开发者指南中的管理 LF 标签以实现元数据访问控制

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateLfTag中的。

以下代码示例演示如何使用 update-table-objects

Amazon CLI

修改受管辖表格的对象

以下update-table-objects示例将提供的 S3 对象添加到指定的受管辖表中。

aws lakeformation update-table-objects \ --cli-input-json file://input.json

input.json 的内容:

{ "CatalogId": "012345678901", "DatabaseName": "tpc", "TableName": "dl_tpc_household_demographics_gov", "TransactionId": "12347a9f75424b9b915f6ff201d2a190", "WriteOperations": [{ "AddObject": { "Uri": "s3://lf-data-lake-012345678901/target/dl_tpc_household_demographics_gov/run-unnamed-1-part-block-0-r-00000-snappy-ff26b17504414fe88b302cd795eabd00.parquet", "ETag": "1234ab1fc50a316b149b4e1f21a73800", "Size": 42200 } }] }

此命令不生成任何输出。

有关更多信息,请参阅 Lake Formati on 开发者指南中的在事务中读取和写入数据Amazon 湖

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateTableObjects中的。