-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathroute53dump
executable file
·41 lines (32 loc) · 959 Bytes
/
route53dump
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
#!/usr/bin/env python3
# This script dumps a Route53 zone in BIND format
import sys
import boto3
import tabulate
# Create a Route53 client
client = boto3.client('route53')
# Get the zone name from the command line
zone_name = sys.argv[1].rstrip('.')
# Get the zone ID
response = client.list_hosted_zones_by_name(
DNSName=zone_name,
MaxItems='1'
)
zone_id = response['HostedZones'][0]['Id']
# Get the zone contents
response = client.list_resource_record_sets(
HostedZoneId=zone_id
)
# Output the zone contents in bind format
data = []
for record in response['ResourceRecordSets']:
for value in record['ResourceRecords']:
data.append({
'Name': record['Name'],
'Class': 'IN',
'Type': record['Type'],
'TTL': record['TTL'],
'Value': value['Value']
})
# use tabulate to print the records in bind format, no headers
print(tabulate.tabulate(data, tablefmt='plain'))