How to use Boto3 to get the security configuration/encryption settings of a catalog from AWS Glue Data Catalog?

AWS Glue Data Catalog stores metadata about your data sources and provides encryption settings for securing your catalog data. You can retrieve these security configurations using boto3 library with the get_data_catalog_encryption_settings() method.

Prerequisites

Before retrieving encryption settings, ensure you have ?

  • AWS credentials configured (access key, secret key)
  • Proper IAM permissions for AWS Glue operations
  • boto3 library installed: pip install boto3

Method Parameters

The get_data_catalog_encryption_settings() method accepts ?

  • CatalogId (optional): AWS account ID. If not provided, uses your current account

Implementation

Here's how to retrieve the security configuration of a catalog ?

import boto3
from botocore.exceptions import ClientError

def retrieves_encryption_setting(catalog_id=None):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.get_data_catalog_encryption_settings(CatalogId=catalog_id)
        return response
    except ClientError as e:
        raise Exception("boto3 client error in retrieves_encryption_setting: " + e.__str__())
    except Exception as e:
        raise Exception("Unexpected error in retrieves_encryption_setting: " + e.__str__())

print(retrieves_encryption_setting())

Output

{'DataCatalogEncryptionSettings': {'EncryptionAtRest':
{'CatalogEncryptionMode': 'SSE-KMS'}, 'ConnectionPasswordEncryption':
{'ReturnConnectionPasswordEncrypted': True}}, 'ResponseMetadata':
{'RequestId': '5ffc0dbb***************7c', 'HTTPStatusCode': 200,
'HTTPHeaders': {'date': 'Sun, 28 Feb 2021 12:22:16 GMT', 'content-type':
'application/x-amz-json-1.1', 'content-length': '166', 'connection':
'keep-alive', 'x-amzn-requestid': '5ffc0dbb********************7c'},
'RetryAttempts': 0}}

Understanding the Response

The response contains two main encryption settings ?

Setting Description Purpose
EncryptionAtRest Catalog metadata encryption Protects stored catalog data
ConnectionPasswordEncryption Connection password encryption Secures database passwords

Enhanced Implementation

Here's an improved version that extracts specific encryption details ?

import boto3
from botocore.exceptions import ClientError

def get_catalog_encryption_details(catalog_id=None):
    """
    Retrieve and parse AWS Glue Data Catalog encryption settings
    """
    try:
        glue_client = boto3.client('glue')
        response = glue_client.get_data_catalog_encryption_settings(CatalogId=catalog_id)
        
        # Extract encryption settings
        settings = response['DataCatalogEncryptionSettings']
        
        # Parse encryption at rest
        encryption_at_rest = settings.get('EncryptionAtRest', {})
        catalog_mode = encryption_at_rest.get('CatalogEncryptionMode', 'DISABLED')
        
        # Parse connection password encryption
        conn_encryption = settings.get('ConnectionPasswordEncryption', {})
        password_encrypted = conn_encryption.get('ReturnConnectionPasswordEncrypted', False)
        
        return {
            'catalog_encryption_mode': catalog_mode,
            'password_encryption_enabled': password_encrypted,
            'raw_response': settings
        }
        
    except ClientError as e:
        print(f"AWS Client Error: {e}")
        return None
    except Exception as e:
        print(f"Unexpected Error: {e}")
        return None

# Usage example
result = get_catalog_encryption_details()
if result:
    print(f"Catalog Encryption Mode: {result['catalog_encryption_mode']}")
    print(f"Password Encryption: {result['password_encryption_enabled']}")

Common Encryption Modes

  • SSE-KMS: Server-side encryption using AWS Key Management Service
  • SSE-S3: Server-side encryption using Amazon S3 managed keys
  • DISABLED: No encryption enabled

Conclusion

Use get_data_catalog_encryption_settings() to retrieve AWS Glue catalog security configurations. The response provides details about encryption at rest and connection password encryption settings for your data catalog.

Updated on: 2026-03-25T18:18:13+05:30

375 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements