How to use Boto3 to get the details of a specified security configuration present in AWS Glue Security?

AWS Glue security configurations define encryption and other security settings for jobs and crawlers. You can retrieve details of a specific security configuration using the get_security_configuration() method from the Boto3 Glue client.

Problem Statement

Use boto3 library in Python to get details of a specified security configuration present in AWS Glue Security.

Example Use Case

Get details of a specified security configuration ('job-security-settings') present in AWS Glue Security.

Approach

Step 1 − Import boto3 and botocore exceptions to handle exceptions.

Step 2security_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.

Implementation

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

Key Points

  • The get_security_configuration() method requires the Name parameter
  • Returns detailed information including encryption configuration and metadata
  • Proper exception handling is essential for AWS API calls
  • Ensure proper AWS credentials are configured before running

Conclusion

Using Boto3's get_security_configuration() method allows you to retrieve detailed security settings for AWS Glue jobs. Always include proper exception handling when working with AWS APIs.

Updated on: 2026-03-25T18:19:32+05:30

267 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements