- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use Boto3 to get the details of a specified security configuration present in AWS Glue Security?
Problem Statement − Use boto3 library in Python to get details of a specified security configuration present in AWS Glue Security.
Example − Get details of a specified security configuration (‘job-security-settings’) present in AWS Glue Security.
Approach/Algorithm to solve this problem
Step 1 − Import boto3 and botocore exceptions to handle exceptions.
Step 2 − security_name is the mandatory parameter whose configuration details needs to be fetched.
Step 3 − Create an AWS session using boto3 library. Make sure region_name is mentioned in default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.
Step 4 − Create an AWS client for glue.
Step 5 − Now use get_security_configuration function and pass the security_name as Name parameter.
Step 6 − It returns the configuration of a given security.
Step 7 − Handle the generic exception if something went wrong while checking the job.
Example
Use the following code to fetch configuration of given security −
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"))
Output
{'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}}