Skip to content

Instantly share code, notes, and snippets.



Last active Oct 8, 2015
What would you like to do?
DynamicDNS For Use With AmazonRoute53
#!/usr/bin/env python
import stun
import socket
import route53
domainName = ''#Make sure this is a FQDN i.e. it should have a '.' at the end.
access_id = ''
secret_key = ''
hostedZoneID = '' #Get this from your aws account
#This can be changed to look at the aws record if you dont want to make a socket call to the machine.
oldIP = socket.gethostbyname(domainName)
oldIP = 'Not found'
nat_type, current_ip, external_port = stun.get_ip_info()
conn = route53.connect(
zone = conn.get_hosted_zone_by_id(hostedZoneID)
#Find the recordset we are looking for and store it
recset = None
for record_set in zone.record_sets:
if == domainName:
recset = record_set
#if the IP has changed save it
if oldIP.__str__() != current_ip.__str__():
#Print the old and current IP for logging purposes
print oldIP.__str__()
print current_ip.__str__()
#Overwrite the existing records , this should always be a single IP as string
recset.records = [current_ip.__str__()]
print 'updated recset'

This comment has been minimized.

Copy link
Owner Author

@RC1140 RC1140 commented Sep 25, 2013

If you are unable to install pytz because of issues with pip , add the following to a file called requirements.txt
and then install with with , pip install -r requirements.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment