如何使用 Boto3 获取 AWS Glue 安全性中所有安全配置的详细信息?


问题陈述 − 在 Python 中使用 boto3 库获取 AWS Glue 安全性中所有安全配置的详细信息。

示例 − 获取 AWS Glue 安全性中所有安全配置的详细信息。

解决此问题的方法/算法

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

步骤 2 − 没有参数。它获取用户 AWS Glue 安全性中存在的全部安全配置。

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

步骤 4 − 为 Glue 创建 AWS 客户端。

步骤 5 − 现在使用 get_security_configurations 函数。

步骤 6 − 它返回所有安全性的配置。

步骤 7 − 如果在检查作业时出现任何错误,请处理通用异常。

示例

使用以下代码获取所有安全性的配置 −

import boto3
from botocore.exceptions import ClientError

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

输出

{'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}}

更新于: 2021年3月23日

85 次查看

启动您的 职业生涯

通过完成课程获得认证

开始学习
广告

© . All rights reserved.