Skip to content

Instantly share code, notes, and snippets.

@pgehres
Created June 26, 2015 05:41
Show Gist options
  • Save pgehres/59a0764645cb2f2f411c to your computer and use it in GitHub Desktop.
Save pgehres/59a0764645cb2f2f411c to your computer and use it in GitHub Desktop.
Route53 dynamics DNS
ZONE_ID = "<ZONE ID>"
DOMAIN_NAME = "host.name.com." # keep ending period
from boto.route53.connection import Route53Connection
from boto.route53.record import ResourceRecordSets
import requests
import sys
ip = requests.get("http://httpbin.org/ip").json()['origin']
# The credentials are located in ~/.boto
conn = Route53Connection()
record = conn.get_all_rrsets(ZONE_ID, 'A', DOMAIN_NAME, maxitems=1)[0]
if not record.name == DOMAIN_NAME:
sys.exit(0)
old_ip = record.resource_records[0]
if ip == old_ip:
sys.exit(0)
hosted_zone = conn.get_hosted_zone(ZONE_ID)
zone = conn.get_zone(hosted_zone['GetHostedZoneResponse']['HostedZone']['Name'])
zone.update_a(
name=DOMAIN_NAME,
value=ip,
ttl=record.ttl,
identifier=record.identifier
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment