Share this post
FaceBook  Twitter  

While working with the boto python library for AWS, I was unable to find any examples of code for manipulating route53 records. Here are a few examples of how the library can be used. Bear in mind that changes to DNS will not immediately be propagated to DNS servers. You have to wait until the Time To Live (TTL) has expired before a DNS server will fetch the updated record from the authoritative name server. The default TTL for the boto library is 600s (10 minutes) but you can modify this using the ttl parameter in the add_change method. To check the remaining TTL on a record, use the 'dig' command.

Creating a connection and getting the record sets

First, you need to create a connection:

conn = boto.connect_route53()

Then, get the ResourceRecordSet. You need to get the Hosted Zone ID after you've added the domain in route53:

changes = ResourceRecordSets(conn, "G5LEP7LWYS8WL2")

Adding an 'A' record

Add the record, and value, and commit the result:

change = changes.add_change("CREATE", "", "A")
result = change.commit()

The result is the new resourceRecordSet. CNAMEs can be added in the same way, just replace the 'A' with 'CNAME' and the value with the target domain name.

Adding an 'MX' record

Add MX values, which can contain multiple, prioritised values, like so:

change = changes.add_change("CREATE", "", "MX")
result - change.commit()

Deleting records

Delete records by creating a new change type (You need the value which the record is currently pointing to):

change = changes.add_change("DELETE", "", "A")
result = changes.commit()