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

boto3pythonserver side programmingprogramming

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

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

解决此问题的方法/算法

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

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

步骤 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}}

相关文章