如何使用 Boto3 獲取 AWS Glue Security 中指定安全配置的詳細資訊?
問題陳述 − 使用 Python 中的 boto3 庫獲取 AWS Glue Security 中指定安全配置的詳細資訊。
示例 − 獲取 AWS Glue Security 中指定安全配置('job-security-settings')的詳細資訊。
解決此問題的方法/演算法
步驟 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("boto3 client error in get_detail_security_configuration: " + e.__str__())
except Exception as e:
raise Exception( "Unexpected error in 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}}
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP