如何使用Boto3获取AWS Glue安全中指定安全配置的详细信息?
问题描述 − 使用Python中的boto3库获取AWS Glue安全中指定安全配置的详细信息。
示例 − 获取AWS Glue安全中指定安全配置(“job-security-settings”)的详细信息。
更多Python相关文章,请阅读:Python 教程
解决此问题的方法/算法
步骤1 − 导入boto3和botocore异常以处理异常。
步骤2 − security_name 是必需的参数,需要获取其配置详细信息。
步骤3 − 使用boto3库创建AWS会话。确保在默认配置文件中提及了 region_name 。如果未提及,则在创建会话时明确传递 region_name 。
步骤4 − 创建glue的AWS客户端。
步骤5 − 现在使用get_security_configuration函数并传递 security_name 作为Name参数。
步骤6 − 它返回给定安全的配置。
步骤7 − 如果在检查作业时出现问题,请处理通用异常。
示例
使用以下代码获取给定安全的配置−
import boto3
from botocore.exceptions import ClientError
def get_detail_security_configuration(security_name):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_security_configuration(Name=security_name)
return response
except ClientError as e:
raise Exception("在get_detail_security_configuration中发生boto3客户端错误: " + e.__str__())
except Exception as e:
raise Exception( "在get_detail_security_configuration中发生意外错误: " + e.__str__())
print(get_detail_security_configuration("job-security-settings"))
输出
{'SecurityConfiguration': {'Name': 'job-security-settings',
'CreatedTimeStamp': datetime.datetime(2020, 9, 24, 1, 53, 21, 265000,
tzinfo=tzlocal()), 'EncryptionConfiguration': {'S3Encryption':
[{'S3EncryptionMode': 'SSE-KMS', 'KmsKeyArn': 'arn:aws:kms:us-east1:**************:key/************-bd27-f3ec3b590d0f'}]}},
'ResponseMetadata': {'RequestId': 'b1***************-afd048ed7d07',
'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Mon, 01 Mar 2021
05:48:47 GMT', 'content-type': 'application/x-amz-json-1.1', 'contentlength': '417', 'connection': 'keep-alive', 'x-amzn-requestid':
'b1*******************-afd048ed7d07'}, 'RetryAttempts': 0}}
极客教程