Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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
boto3library installed
Approach
The solution follows these steps ?
- Import required libraries (
boto3and exception handling) - Create an AWS session and Glue client
- Call
get_connection()with the connection name - 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.
Advertisements
