How to get all resource records from route 53 using boto?

I am writing a script that ensures that all EC2 instances have DNS records and all DNS records point to valid EC2 instances.

My approach is to try and get all the resource records for our domain so that I can iterate through the list while checking the instance name.

However, getting all resource records doesn't seem to be very easy! The documentation for GET ListResourceRecordSets seems to suggest that it can do what I want, and the boto equivalent seems to be get_all_rrsets ... but it doesn't work as I expected.

For example, if I go:

r53 = boto.connect_route53()
zones = r53.get_zones()
fooA = r53.get_all_rrsets(zones[0][id], name="a")

      

then i get 100 results. If I then go:

fooB = r53.get_all_rrsets(zones[0][id], name="b")

      

I am getting the same 100 results. I misunderstood and get_all_rrsets not showing up in ListResourceRecordSets?

Any suggestions on how I can get all the entries from route 53?

Update: cli53 ( https://github.com/barnybug/cli53/blob/master/cli53/client.py ) can do this through its function to export zone route 53 in BIND format (cmd_export). However, my Python skills are not strong enough for me to understand how this code works!

Thank.

+3


source to share


1 answer


get_all_rrsets

returns a ResourceRecordSets

which comes from the Python list class. By default, 100 records are returned. So if you use the result as a list, it will have 100 entries. What you want to do instead is the following:

r53records = r53.get_all_rrsets(zones[0][id])
for record in r53records:
    # do something with each record here

      

Alternatively, if you want all entries in the list:



records = [r for r in r53.get_all_rrsets(zones[0][id]))]

      

When iterating using a for loop or a list, Boto will retrieve additional records (up to) 100 records at a time as needed.

+4


source







All Articles