문제 설명 − Python에서 boto3 라이브러리를 사용하여 AWS Glue Security에 있는 모든 보안 구성의 세부 정보를 얻습니다.
예 − AWS Glue Security에 있는 모든 보안 구성의 세부 정보를 가져옵니다.
이 문제를 해결하기 위한 접근 방식/알고리즘
1단계 − boto3 및 botocore 예외를 가져와 예외를 처리합니다.
2단계 - 매개변수가 없습니다. 사용자의 AWS Glue Security에 있는 모든 보안 구성을 가져옵니다.
3단계 − boto3 라이브러리를 사용하여 AWS 세션을 생성합니다. region_name이 기본 프로필에 언급되어 있는지 확인하십시오. 언급되지 않은 경우 세션을 생성하는 동안 region_name을 명시적으로 전달하십시오.
4단계 − 글루용 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}}