Boto for Amazon Route53

Tips N Tricks August 20th, 2011

Route53 is Amazon’s scalable Domain Name System (DNS) web service. If you are already having your infrastructure on Amazon’s EC2 infrastructure, it is an easy move from your existing DNS provider to Route53.

Boto is a python package that provides a number of python interfaces to interract with Amazon Web Services (AWS) like EC2, RDS, ELB, etc. Boto interface for Route53 is pretty simple. Boto allows adding ‘A’, ‘AAAA’, ‘TXT’, ‘CNAME’, ‘MX’, ‘PTR’, ‘SRV’ and ‘SPF’ records to Route53.

Each zone that is created on Route53 has a zone id which can be obtained by using the command line utility provided by amazon.

% ./bin/route53 ls
============================================
| ID: ZXXXXXXXXXXXXXX
| Name: yourdomain.com.
| Ref: xxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx
============================================
{}

Basic authentication on boto for Route53

The following step is required for all boto operations with route53. In python terminal use the following commands:

>>> import boto
>>> from boto import route53
>>> key = ‘AAES5WCQQBW5XZ2DAA’
>>> access = ‘DMJsjdlkr0OHnrwqEsGkksjweosbg/yeISOPEOdnsK’
>>> route53 = Route53Connection(key, access)
>>> results = route53.get_all_hosted_zones()
>>> results
{u’ListHostedZonesResponse’: {u’HostedZones’: [{u'CallerReference': u'6000r000-b00-0000-8000-46000000c', u'Config': {}, u'Id': u'/hostedzone/ZXXXXXXXXXXXXXX', u'Name': u'yourdomain.com.'}], u’IsTruncated’: u’false’, u’MaxItems’: u’100′}}

Adding A record on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “yourdomainname.com”,”A”)
>>> change.add_value(“45.34.22.455″) #your ip address
>>> changes.commit()

Adding CNAME on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “subdomain.yourdomainname.com”, “CNAME”)
>>> change.add_value(“some_dns_name”)
>>> changes.commit()

Adding TXT Record on Route53 with Boto

Note: All text records will require you to add strings as value. Note the extra quotes around the text value, else expect to see an error as below:

Invalid Resource Record: FATAL problem: InvalidTXTRDATA encountered at “\”v=spf1 ip4:64.64.9.245 a mx ~all\”

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “yourdomainname.com”, “TXT”)
>>> change.add_value(“\”v=spf1 mx ptr include:mail and other text a ~all\”“)
>>> changes.commit()

Deleting CNAME on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53()
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“DELETE”, “subdomain.yourdomainname.com”, “CNAME”)
>>> change.add_value(“some_dns_name”) #Note: This value has to match exactly with the record
>>> changes.commit()

Python Video Tutorials

Uncategorized December 6th, 2009

Getting started with python programming is really easy given the number of tutorials available and the brilliant python documentation. Yet, it is very typical for someone to look for python video tutorials as it just makes the learning even more easier. here is a wonderful series of video tutorials that takes you from being a novice to another level of novice in python programming. It is a wonderful start for someone who is just stepping into programming for the first time.