Created
June 26, 2015 05:41
-
-
Save pgehres/59a0764645cb2f2f411c to your computer and use it in GitHub Desktop.
Route53 dynamics DNS
This file contains 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
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