Last active
September 29, 2023 10:55
-
-
Save estahn/33ee9f0ecede6416a168489a7a24ee24 to your computer and use it in GitHub Desktop.
Export AWS Route53 Domains to a CSV for Excel people
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Export AWS Route53 Domains to a CSV for Excel people | |
# | |
# Usage: | |
# | |
# python3 <(wget -q -O - https://gist.github.com/estahn/33ee9f0ecede6416a168489a7a24ee24/raw/5eef9122e573ff23bcd40732856565c37c708efd/domains.py) | |
# | |
from itertools import chain, starmap | |
import pandas as pd | |
from pandas.io.json import json_normalize #package for flattening json in pandas df | |
import boto3 | |
listofdomains = [] | |
client = boto3.client('route53domains', region_name='us-east-1') | |
p = client.get_paginator('list_domains') | |
for page in p.paginate(): | |
for domain in page['Domains']: | |
domain_detail = client.get_domain_detail(DomainName=domain['DomainName']) | |
# Remove response data, so it doesn't make it into the spreadsheet | |
del domain_detail['ResponseMetadata'] | |
# Re-map "ExtraParams" to flatten the JSON for the spreadsheet | |
for c in ['RegistrantContact', 'TechContact', 'AdminContact']: | |
for p in domain_detail[c]['ExtraParams']: | |
domain_detail[c][p['Name']] = p['Value'] | |
del domain_detail[c]['ExtraParams'] | |
listofdomains.append(domain_detail) | |
df = pd.json_normalize(listofdomains) | |
df.to_csv (r'domains.csv', index = False, header=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment