如何使用Boto3从AWS Glue Data Catalog获取目录的安全配置/加密设置?

如何使用Boto3从AWS Glue Data Catalog获取目录的安全配置/加密设置?

问题陈述 − 使用Python中的boto3库检索目录的安全配置/加密设置。

示例 − 检索目录的安全配置/加密设置。

更多Python相关文章,请阅读:Python 教程

解决此问题的方法/算法

步骤1 − 导入boto3和botocore异常以处理异常。

步骤2catalog_id 是可选参数。如果未提供,它将获取用户AWS帐户的详细信息。

步骤3 − 使用boto3库创建AWS会话。确保在默认配置文件中提到了region_name。如果没有提到,则在创建会话时明确传递region_name。

步骤4 − 创建glue的AWS客户端。

步骤5 − 现在使用 get_data_catalog_encryption_settings 函数,并将 catalog_id 作为CatalogId参数传递。

步骤6 − 它返回加密设置的详细信息。

步骤7 − 处理常规异常,如果在检查作业时出现问题。

示例

使用以下代码检索目录的安全配置/加密设置-

import boto3
from botocore.exceptions import ClientError

def retrieves_encryption_setting(catalog_id=None)
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.get_data_catalog_encryption_settings(CatalogId = catalog_id)
        return response
    except ClientError as e:
        raise Exception("boto3 client error in retrieves_encryption_setting: " + e.__str__())
    except Exception as e:
        raise Exception("Unexpected error in retrieves_encryption_setting: " + e.__str__())
print(retrieves_encryption_setting())

输出

{'DataCatalogEncryptionSettings': {'EncryptionAtRest':
{'CatalogEncryptionMode': 'SSE-KMS'}, 'ConnectionPasswordEncryption':
{'ReturnConnectionPasswordEncrypted': True}}, 'ResponseMetadata':
{'RequestId': '5ffc0dbb***************7c', 'HTTPStatusCode': 200,
'HTTPHeaders': {'date': 'Sun, 28 Feb 2021 12:22:16 GMT', 'content-type':
'application/x-amz-json-1.1', 'content-length': '166', 'connection':
'keep-alive', 'x-amzn-requestid': '5ffc0dbb********************7c'},
'RetryAttempts': 0}}

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程