- 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 get the details of all the databases from AWS Glue Data Catalog?
Problem Statement − Use boto3 library in Python to retrieve the definition of all the databases.
Example − Retrieve the definition of all the databases.
Approach/Algorithm to solve this problem
Step 1 − Import boto3 and botocore exceptions to handle exceptions.
Step 2 − There is no parameter.
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_databases function.
Step 6 − It returns the definition of all databases present in user’s account.
Step 7 − Handle the generic exception if something went wrong while checking the job.
Example
Use the following code to retrieve the definition of all the databases −
import boto3 from botocore.exceptions import ClientError def retrieves_all_database_details() session = boto3.session.Session() glue_client = session.client('glue') try: response = glue_client.get_databases() return response except ClientError as e: raise Exception("boto3 client error in retrieves_all_database_details: " + e.__str__()) except Exception as e: raise Exception("Unexpected error in retrieves_all_database_details: " + e.__str__()) print(retrieves_all_database_details())
Output
{'DatabaseList': [ {'Name': 'QA-test', 'CreateTime': datetime.datetime(2020, 11, 18, 14, 24, 46, tzinfo=tzlocal())}, {'Name': 'custdb', 'CreateTime': datetime.datetime(2020, 8, 31, 20, 30, 9, tzinfo=tzlocal())}, {'Name': 'default', 'Description': 'Default Hive database', 'LocationUri': 'hdfs://ip- ************.ec2.internal:****/user/hive/warehouse', 'CreateTime': datetime.datetime(2018, 5, 25, 16, 4, 54, tzinfo=tzlocal())},'NextToken': 'eyJsYXN0RXZhbHVhdGVkS2V5Ijp7IkhBU0hfS0VZIjp7InMiOiJuLjc4MjI1ODQ4NTg0MSJ 9LCJSQU5HRV9LRVkiOnsicyI6InN************Mjk3NywibmFub3MiOjIyNTA********* **NvbnRleHQiOmZhbHNlfQ==', 'ResponseMetadata': {'RequestId': 'fa0a2069-***********-a0617', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 28 Feb 2021 12:49:37 GMT', 'content-type': 'application/x-amz-json-1.1', 'contentlength': '25749', 'connection': 'keep-alive', 'x-amzn-requestid': 'fa0a2069-************a0617'}, 'RetryAttempts': 0}}
- Related Articles
- How to use Boto3 to get the details of a classifier from AWS Glue Data catalog?
- How to use Boto3 to get the details of a connection from AWS Glue Data catalog?
- How to use Boto3 to get the details of a database from AWS Glue Data Catalog?
- How to use Boto3 to get the details of all classifiers available in AWS Glue Data catalog?
- How to use Boto3 to get the details of all connection available in AWS Glue Data catalog?
- How to get the details of a trigger from AWS Glue Data catalog using Boto3
- How to get the details of all the triggers associated with a job from AWS Glue Data catalog using Boto3
- How to use Boto3 to get the details of a job that is bookmarked in AWS Glue Data Catalog?
- How to use Boto3 to get the security configuration/encryption settings of a catalog from AWS Glue Data Catalog?
- How to use Boto3 to update the details of a workflow in AWS Glue Catalog
- How to use Boto3 to get the metrics of one/manyspecified crawler from AWS Glue Data Catalog?
- How to use Boto3 to get the table definition of a database from AWS Glue Data Catalog?
- How to get the details of a user-defined function in a database from AWS Glue Data catalog using Boto3
- How to use Boto3 to delete a crawler from AWS Glue Data Catalog?
- How to use Boto3 to delete a table from AWS Glue Data catalog?
