Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from prettytable import PrettyTable
- import boto3
- list_of_tables = [
- {
- "db": "rds",
- "tables":
- [
- "bill_",
- "set_",
- "my_",
- "ocpi_",
- "sub_",
- "trff_",
- "ecl_",
- "hub_",
- "avail_",
- "cn_"
- ],
- "isprefix": True
- },
- {
- "db": "salesforce",
- "tables":
- [
- "sf_payment_account__c",
- "payment_account_data_errors",
- "payment_accounts_view"
- ],
- "isprefix": False
- }
- ]
- list_of_locations = []
- glue_client = boto3.client("glue")
- for income in list_of_tables:
- resp = glue_client.get_tables(DatabaseName=income['db'])
- for glue_table in resp['TableList']:
- glue_table_name = str(glue_table['Name'])
- if income['isprefix']:
- for prefix in income['tables']:
- if glue_table_name.startswith(prefix):
- list_of_locations.append({"db": income['db'],
- "table": glue_table_name,
- "location": glue_table['StorageDescriptor']['Location']})
- if glue_table_name in income['tables']:
- list_of_locations.append({"db": income['db'],
- "table": glue_table_name,
- "location": glue_table['StorageDescriptor']['Location']})
- print(list_of_locations)
- result = PrettyTable()
- result.field_names = ["Database", "Table", "S3"]
- for location in list_of_locations:
- result.add_row([location['db'],
- location['table'],
- location['location']])
- print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement