

# 使用 AWS CLI 的 Lake Formation 示例
<a name="cli_lakeformation_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface与 Lake Formation 结合使用，来执行操作和实现常见场景。

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

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

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `add-lf-tags-to-resource`
<a name="lakeformation_AddLfTagsToResource_cli_topic"></a>

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

**AWS CLI**  
**将一个或多个 LF 标签附加到现有资源**  
以下 `add-lf-tags-to-resource` 示例将给定 LF 标签附加到表资源。  

```
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": []
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[为数据目录资源分配 LF 标签](https://docs.aws.amazon.com/lake-formation/latest/dg/TBAC-assigning-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [AddLfTagsToResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/add-lf-tags-to-resource.html)。

### `batch-grant-permissions`
<a name="lakeformation_BatchGrantPermissions_cli_topic"></a>

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

**AWS 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": []
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchGrantPermissions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/batch-grant-permissions.html)。

### `batch-revoke-permissions`
<a name="lakeformation_BatchRevokePermissions_cli_topic"></a>

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

**AWS 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": []
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchRevokePermissions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/batch-revoke-permissions.html)。

### `cancel-transaction`
<a name="lakeformation_CancelTransaction_cli_topic"></a>

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

**AWS CLI**  
**取消事务**  
以下 `cancel-transaction` 示例取消事务。  

```
aws lakeformation cancel-transaction \
    --transaction-id='b014d972ca8347b89825e33c5774aec4'
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CancelTransaction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/cancel-transaction.html)。

### `commit-transaction`
<a name="lakeformation_CommitTransaction_cli_topic"></a>

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

**AWS CLI**  
**提交事务**  
以下 `commit-transaction` 示例提交事务。  

```
aws lakeformation commit-transaction \
    --transaction-id='b014d972ca8347b89825e33c5774aec4'
```
输出：  

```
{
    "TransactionStatus": "committed"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CommitTransaction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/commit-transaction.html)。

### `create-data-cells-filter`
<a name="lakeformation_CreateDataCellsFilter_cli_topic"></a>

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

**AWS 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"
    }
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的 [Lake Formation 中的数据筛选和单元格级安全性](https://docs.aws.amazon.com/lake-formation/latest/dg/data-filtering.html)。  
**示例 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"
    }
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的 [Lake Formation 中的数据筛选和单元格级安全性](https://docs.aws.amazon.com/lake-formation/latest/dg/data-filtering.html)。  
**示例 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"
    }
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的 [Lake Formation 中的数据筛选和单元格级安全性](https://docs.aws.amazon.com/lake-formation/latest/dg/data-filtering.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateDataCellsFilter](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/create-data-cells-filter.html)。

### `create-lf-tag`
<a name="lakeformation_CreateLfTag_cli_topic"></a>

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

**AWS CLI**  
**创建 LF 标签**  
以下 `create-lf-tag` 示例使用指定名称和值创建一个 LF 标签。  

```
aws lakeformation create-lf-tag \
    --catalog-id '123456789111' \
    --tag-key 'usergroup' \
    --tag-values '["developer","analyst","campaign"]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 LF 标签以进行元数据访问控制](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [CreateLfTag](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/create-lf-tag.html)**。

### `delete-data-cells-filter`
<a name="lakeformation_DeleteDataCellsFilter_cli_topic"></a>

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

**AWS 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"
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的 [Lake Formation 中的数据筛选和单元格级安全性](https://docs.aws.amazon.com/lake-formation/latest/dg/data-filtering.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteDataCellsFilter](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/delete-data-cells-filter.html)。

### `delete-lf-tag`
<a name="lakeformation_DeleteLfTag_cli_topic"></a>

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

**AWS CLI**  
**删除 LF 标签定义**  
以下 `delete-lf-tag` 示例删除 LF 标签定义。  

```
aws lakeformation delete-lf-tag \
    --catalog-id '123456789111' \
    --tag-key 'usergroup'
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 LF 标签以进行元数据访问控制](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [DeleteLfTag](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/delete-lf-tag.html)**。

### `delete-objects-on-cancel`
<a name="lakeformation_DeleteObjectsOnCancel_cli_topic"></a>

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

**AWS 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"
    }]
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteObjectsOnCancel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/delete-objects-on-cancel.html)。

### `deregister-resource`
<a name="lakeformation_DeregisterResource_cli_topic"></a>

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

**AWS 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"
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[向数据湖添加 Amazon S3 位置](https://docs.aws.amazon.com/lake-formation/latest/dg/register-data-lake.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeregisterResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/deregister-resource.html)。

### `describe-transaction`
<a name="lakeformation_DescribeTransaction_cli_topic"></a>

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

**AWS 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"
    }
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeTransaction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/describe-transaction.html)。

### `extend-transaction`
<a name="lakeformation_ExtendTransaction_cli_topic"></a>

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

**AWS CLI**  
**扩展事务**  
以下 `extend-transaction` 示例扩展事务。  

```
aws lakeformation extend-transaction \
    --transaction-id='8cb4b1a7cc8d486fbaca9a64e7d9f5ce'
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ExtendTransaction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/extend-transaction.html)。

### `get-data-lake-settings`
<a name="lakeformation_GetDataLakeSettings_cli_topic"></a>

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

**AWS CLI**  
**检索 AWS 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"
        ]
    }
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[更改数据湖的默认安全设置](https://docs.aws.amazon.com/lake-formation/latest/dg/change-settings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetDataLakeSettings](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-data-lake-settings.html)。

### `get-effective-permissions-for-path`
<a name="lakeformation_GetEffectivePermissionsForPath_cli_topic"></a>

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

**AWS 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=="
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 Lake Formation 权限](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-permissions.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetEffectivePermissionsForPath](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-effective-permissions-for-path.html)。

### `get-lf-tag`
<a name="lakeformation_GetLfTag_cli_topic"></a>

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

**AWS CLI**  
**检索 LF 标签定义**  
以下 `get-lf-tag` 示例检索 LF 标签定义。  

```
aws lakeformation get-lf-tag \
    --catalog-id '123456789111' \
    --tag-key 'usergroup'
```
输出：  

```
{
    "CatalogId": "123456789111",
    "TagKey": "usergroup",
    "TagValues": [
        "analyst",
        "campaign",
        "developer"
    ]
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 LF 标签以进行元数据访问控制](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetLfTag](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-lf-tag.html)。

### `get-query-state`
<a name="lakeformation_GetQueryState_cli_topic"></a>

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

**AWS CLI**  
**检索已提交查询的状态**  
以下 `get-query-state` 示例返回先前提交的查询的状态。  

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

```
{
    "State": "FINISHED"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[事务性数据操作](https://docs.aws.amazon.com/lake-formation/latest/dg/transactions-data-operations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetQueryState](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-query-state.html)。

### `get-query-statistics`
<a name="lakeformation_GetQueryStatistics_cli_topic"></a>

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

**AWS 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"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[事务性数据操作](https://docs.aws.amazon.com/lake-formation/latest/dg/transactions-data-operations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetQueryStatistics](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-query-statistics.html)。

### `get-resource-lf-tags`
<a name="lakeformation_GetResourceLfTags_cli_topic"></a>

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

**AWS CLI**  
**列出 LF 标签**  
以下 `list-lf-tags` 示例返回请求者有权查看的 LF 标签列表。  

```
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"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 LF 标签以进行元数据访问控制](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetResourceLfTags](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-resource-lf-tags.html)。

### `get-table-objects`
<a name="lakeformation_GetTableObjects_cli_topic"></a>

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

**AWS 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
        }]
    }]
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetTableObjects](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-table-objects.html)。

### `get-work-unit-results`
<a name="lakeformation_GetWorkUnitResults_cli_topic"></a>

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

**AWS 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.
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[事务性数据操作](https://docs.aws.amazon.com/lake-formation/latest/dg/transactions-data-operations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetWorkUnitResults](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-work-unit-results.html)。

### `get-work-units`
<a name="lakeformation_GetWorkUnits_cli_topic"></a>

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

**AWS 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"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[事务性数据操作](https://docs.aws.amazon.com/lake-formation/latest/dg/transactions-data-operations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetWorkUnits](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/get-work-units.html)。

### `grant-permissions`
<a name="lakeformation_GrantPermissions_cli_topic"></a>

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

**AWS CLI**  
**示例 1：向主体授予使用 LF 标签的资源的权限**  
以下 `grant-permissions` 示例向主体授予与 LF 标签策略匹配的数据库资源的所有权限。  

```
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"
    ]
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
**示例 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": []
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
**示例 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": []
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
**示例 4：向主体授予 LF 标签权限**  
以下 `grant-permissions` 示例向主体授予 LF 标签的关联权限。  

```
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": []
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
**示例 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": []
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GrantPermissions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/grant-permissions.html)。

### `list-data-cells-filter`
<a name="lakeformation_ListDataCellsFilter_cli_topic"></a>

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

**AWS 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"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的 [Lake Formation 中的数据筛选和单元格级安全性](https://docs.aws.amazon.com/lake-formation/latest/dg/data-filtering.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListDataCellsFilter](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/list-data-cells-filter.html)。

### `list-permissions`
<a name="lakeformation_ListPermissions_cli_topic"></a>

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

**AWS 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"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 Lake Formation 权限](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-permissions.html)。  
**示例 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"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 Lake Formation 权限](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-permissions.html)。  
**示例 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="
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 Lake Formation 权限](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-permissions.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListPermissions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/list-permissions.html)。

### `list-resources`
<a name="lakeformation_ListResources_cli_topic"></a>

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

**AWS 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"
        }
    ]
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 Lake Formation 权限](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-permissions.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/list-resources.html)。

### `list-transactions`
<a name="lakeformation_ListTransactions_cli_topic"></a>

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

**AWS 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=="
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListTransactions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/list-transactions.html)。

### `put-data-lake-settings`
<a name="lakeformation_PutDataLakeSettings_cli_topic"></a>

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

**AWS CLI**  
**设置 AWS 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"]
    }
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[更改数据湖的默认安全设置](https://docs.aws.amazon.com/lake-formation/latest/dg/change-settings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutDataLakeSettings](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/put-data-lake-settings.html)。

### `register-resource`
<a name="lakeformation_RegisterResource_cli_topic"></a>

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

**AWS 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
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[向数据湖添加 Amazon S3 位置](https://docs.aws.amazon.com/lake-formation/latest/dg/register-data-lake.html)。  
**示例 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"
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[向数据湖添加 Amazon S3 位置](https://docs.aws.amazon.com/lake-formation/latest/dg/register-data-lake.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [RegisterResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/register-resource.html)。

### `remove-lf-tags-from-resource`
<a name="lakeformation_RemoveLfTagsFromResource_cli_topic"></a>

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

**AWS CLI**  
**从资源中移除 LF 标签**  
以下 `remove-lf-tags-from-resource` 示例移除与表资源关联的 LF 标签。  

```
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": []
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[为数据目录资源分配 LF 标签](https://docs.aws.amazon.com/lake-formation/latest/dg/TBAC-assigning-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [RemoveLfTagsFromResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/remove-lf-tags-from-resource.html)。

### `revoke-permissions`
<a name="lakeformation_RevokePermissions_cli_topic"></a>

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

**AWS 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": []
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[授予和撤销对数据目录资源的权限](https://docs.aws.amazon.com/lake-formation/latest/dg/granting-catalog-permissions.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [RevokePermissions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/revoke-permissions.html)。

### `search-databases-by-lf-tags`
<a name="lakeformation_SearchDatabasesByLfTags_cli_topic"></a>

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

**AWS CLI**  
**通过 LF 标签搜索数据库资源**  
以下 `search-databases-by-lf-tags` 示例搜索与 LF 标签表达式匹配的数据库资源。  

```
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"
            ]
        }]
    }]
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[查看分配得到某个 LF 标签的资源](https://docs.aws.amazon.com/lake-formation/latest/dg/TBAC-view-tag-resources.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [SearchDatabasesByLfTags](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/search-databases-by-lf-tags.html)。

### `search-tables-by-lf-tags`
<a name="lakeformation_SearchTablesByLfTags_cli_topic"></a>

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

**AWS CLI**  
**通过 LF 标签搜索表资源**  
以下 `search-tables-by-lf-tags` 示例搜索与 LF 标签表达式匹配的表资源。  

```
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"
                    ]
                }]
            }
        ]
    }]
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[查看分配得到某个 LF 标签的资源](https://docs.aws.amazon.com/lake-formation/latest/dg/TBAC-view-tag-resources.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [SearchTablesByLfTags](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/search-tables-by-lf-tags.html)。

### `start-query-planning`
<a name="lakeformation_StartQueryPlanning_cli_topic"></a>

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

**AWS 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"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [StartQueryPlanning](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/start-query-planning.html)**。

### `start-transaction`
<a name="lakeformation_StartTransaction_cli_topic"></a>

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

**AWS CLI**  
**启动新事务**  
以下 `start-transaction` 示例启动一个新事务并返回其事务 ID。  

```
aws lakeformation start-transaction \
    --transaction-type = 'READ_AND_WRITE'
```
输出：  

```
{
    "TransactionId": "b014d972ca8347b89825e33c5774aec4"
}
```
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [StartTransaction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/start-transaction.html)。

### `update-lf-tag`
<a name="lakeformation_UpdateLfTag_cli_topic"></a>

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

**AWS CLI**  
**更新 LF 标签定义**  
以下 `update-lf-tag` 示例更新 LF 标签定义。  

```
aws lakeformation update-lf-tag \
    --catalog-id '123456789111' \
    --tag-key 'usergroup' \
    --tag-values-to-add '["admin"]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[管理 LF 标签以进行元数据访问控制](https://docs.aws.amazon.com/lake-formation/latest/dg/managing-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [UpdateLfTag](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/update-lf-tag.html)**。

### `update-table-objects`
<a name="lakeformation_UpdateTableObjects_cli_topic"></a>

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

**AWS 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
        }
    }]
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[在事务内读写数据湖](https://docs.aws.amazon.com/lake-formation/latest/dg/transaction-ops.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateTableObjects](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lakeformation/update-table-objects.html)。