Created
March 21, 2021 22:51
-
-
Save chrispassas/2906743b300c884a937a01d7e9809293 to your computer and use it in GitHub Desktop.
Route 53 DDNS example python
This file contains hidden or 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
#aws library | |
import boto.route53 | |
import urllib2 | |
import string | |
import datetime | |
print str(datetime.datetime.utcnow())+" - Starting ddns.py" | |
#Credentials | |
aws_access_key_id = 'KkRbWpoyqLHo69dvoskn' | |
aws_secret_access_key = 'VXFvVu0ckOYP22WYxAz9TyoNYC8Rx1WVLVFK3Fyc' | |
domain = 'example.com.' | |
aws_region = 'us-west-2' | |
zone_id = 'Z2DKEZEXAMPLE1' | |
record_name = 'home.example.com | |
#get output from ip.changeip.com | |
url = 'http://ip.changeip.com' | |
req = urllib2.Request(url) | |
res = urllib2.urlopen(req) | |
data = res.read() | |
#grab first line and save to ip | |
lines = string.split(data, '\n') | |
ip = lines[0] | |
print str(datetime.datetime.utcnow())+" - Detected IP:"+ip | |
#Connect to aws | |
conn = boto.route53.connect_to_region(aws_region) | |
#get zone | |
zone = conn.get_hosted_zone_by_name(domain) | |
#get record set | |
record_set = boto.route53.record.ResourceRecordSets(conn,zone_id,'') | |
#get record | |
record = record_set.add_change('UPSERT',record_name,'A',300,zone.Id) | |
#set ip | |
record.add_value(ip) | |
#save | |
record_set.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment