How to use Boto3 to get the details of a connection from AWS Glue Data catalog?

AWS Glue Data Catalog stores connection definitions that can be retrieved using the Boto3 library. This tutorial demonstrates how to fetch connection details using the get_connection() method.

Prerequisites

Before running this code, ensure you have ?

  • AWS credentials configured (via AWS CLI, IAM role, or environment variables)
  • Appropriate IAM permissions for AWS Glue operations
  • The boto3 library installed

Approach

The solution follows these steps ?

  1. Import required libraries (boto3 and exception handling)
  2. Create an AWS session and Glue client
  3. Call get_connection() with the connection name
  4. Handle potential errors gracefully

Implementation

import boto3
from botocore.exceptions import ClientError

def get_details_of_a_connection(connection_name):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.get_connection(Name=connection_name)
        return response
    except ClientError as e:
        raise Exception("boto3 client error in get_details_of_a_connection: " + e.__str__())
    except Exception as e:
        raise Exception("Unexpected error in get_details_of_a_connection: " + e.__str__())

print(get_details_of_a_connection("aurora-poc"))

Output

{'Connection': {'Name': 'aurora-poc', 'ConnectionType': 'JDBC',
'ConnectionProperties': {'JDBC_CONNECTION_URL': 'jdbc:postgresql://abcpostgresql-cluster.cluster-abc.us-east-1.rds.amazonaws.com:0132/abc',
'JDBC_ENFORCE_SSL': 'false', 'PASSWORD': '******', 'USERNAME':
'abc***'}, 'PhysicalConnectionRequirements': {'SubnetId': 'subnet351*****', 'SecurityGroupIdList': ['sg-caa******', 'sg-*************'],
'AvailabilityZone': 'us-east-1c'}, 'CreationTime':
datetime.datetime(2020, 11, 18, 12, 38, 29, 625000, tzinfo=tzlocal()),
'LastUpdatedTime': datetime.datetime(2020, 11, 18, 12, 51, 16, 59000,
tzinfo=tzlocal())}, 'ResponseMetadata': {'RequestId': '6f13524b-4175-
454b-bc60-c7f408967098', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date':
'Sun, 28 Feb 2021 11:19:18 GMT', 'content-type': 'application/x-amzjson-1.1', 'content-length': '523', 'connection': 'keep-alive', 'x-amznrequestid': '6f13524b-*****************7098'}, 'RetryAttempts': 0}}

Key Response Fields

The response contains important connection details ?

  • Name − Connection identifier
  • ConnectionType − Type of connection (JDBC, SFTP, etc.)
  • ConnectionProperties − URL, credentials, and connection settings
  • PhysicalConnectionRequirements − VPC, subnet, and security group details
  • CreationTime/LastUpdatedTime − Timestamp information

Error Handling

Common errors you might encounter ?

  • EntityNotFoundException − Connection doesn't exist
  • InvalidInputException − Invalid connection name format
  • AccessDeniedException − Insufficient IAM permissions

Conclusion

Use Boto3's get_connection() method to retrieve AWS Glue connection details. Always implement proper error handling and ensure appropriate IAM permissions are configured.

Updated on: 2026-03-25T18:17:08+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements