-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute53_dump.py
More file actions
76 lines (49 loc) · 1.81 KB
/
route53_dump.py
File metadata and controls
76 lines (49 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Dump all route53 records
"""
from utils.json_printer import json_printer
from utils.json_writer import json_writer
from utils.session import get_session
PRINT_NAMES = ('A', 'CNAME')
def print_interesting(record):
record_name = record.get('Name', None)
if record.get('Type') not in PRINT_NAMES:
return
if record_name.endswith('internal'):
return
# replace the * at the beginning of the record name
record_name = record_name.replace('*', 'www')
print(record_name)
def dump_route53_records(route53_client, zone_name, zone_id, all_data):
pager = route53_client.get_paginator('list_resource_record_sets')
for page in pager.paginate(HostedZoneId=zone_id):
for record in page['ResourceRecordSets']:
record_name = record.get('Name', None)
if record_name is None:
continue
if record_name in all_data:
continue
record_name = record_name.replace('\\052', '*')
record_name = record_name[:-1]
record['Name'] = record_name
if zone_name not in all_data:
all_data[zone_name] = list()
all_data[zone_name].append(record)
print_interesting(record)
return all_data
def main():
session = get_session()
route53_client = session.client('route53')
zone_info = route53_client.list_hosted_zones()
all_data = dict()
for zone in zone_info.get('HostedZones'):
zone_name = zone['Name']
zone_id = zone['Id']
# remove trailing dot
zone_name = zone_name[:-1]
dump_route53_records(route53_client, zone_name, zone_id, all_data)
json_writer('output/route53_dump.json', all_data)
return all_data
if __name__ == '__main__':
all_data = main()
# json_printer(all_data)