समस्या का विवरण - AWS Glue Security में मौजूद एक निर्दिष्ट सुरक्षा कॉन्फ़िगरेशन का विवरण प्राप्त करने के लिए Python में boto3 लाइब्रेरी का उपयोग करें।
उदाहरण - एडब्ल्यूएस गोंद सुरक्षा में मौजूद एक निर्दिष्ट सुरक्षा कॉन्फ़िगरेशन ('नौकरी-सुरक्षा-सेटिंग्स') का विवरण प्राप्त करें।
इस समस्या को हल करने के लिए दृष्टिकोण/एल्गोरिदम
चरण 1 - अपवादों को संभालने के लिए boto3 और botocore अपवाद आयात करें।
चरण 2 - सुरक्षा_नाम अनिवार्य पैरामीटर है जिसका कॉन्फ़िगरेशन विवरण प्राप्त करने की आवश्यकता है।
चरण 3 - boto3 लाइब्रेरी का उपयोग करके AWS सत्र बनाएं। सुनिश्चित करें कि क्षेत्र_नाम डिफ़ॉल्ट प्रोफ़ाइल में उल्लेख किया गया है। यदि इसका उल्लेख नहीं है, तो स्पष्ट रूप से region_name . पास करें सत्र बनाते समय।
चरण 4 - गोंद के लिए AWS क्लाइंट बनाएं।
चरण 5 - अब get_security_configuration फ़ंक्शन का उपयोग करें और security_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}}