-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute53-update.py
39 lines (32 loc) · 1.22 KB
/
route53-update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import boto.route53
import urllib2
import socket
####################################
# Crude script to update Route53 DNS
# consider it a poor-mans dyndns
####################################
AWSKEY =
AWSSECRET =
HOSTNAME = 'mtbethelfirehouse'
DOMAIN = 'warrenfire.org'
REGION = 'us-east-1'
IPWEBSITE = 'http://eth0.me'
existing = socket.gethostbyname(HOSTNAME + '.' + DOMAIN)
response = urllib2.urlopen(IPWEBSITE)
page = response.read().strip('\n')
if page != existing:
print "%s not equal to %s" % (page, existing)
conn = boto.route53.connection.Route53Connection(aws_access_key_id=AWSKEY, \
aws_secret_access_key=AWSSECRET)
zone = conn.get_zone(DOMAIN)
change = boto.route53.record.ResourceRecordSets(conn, zone.id)
FQDN = HOSTNAME + '.' + DOMAIN
change.add_change_record("UPSERT",
boto.route53.record.Record(name = FQDN,
type="A",
resource_records=[page]))
change.commit()
print "IP address has been updated %s.%s is recorded as %s" % (HOSTNAME, DOMAIN, page)
else:
print "All systems OK %s.%s is recorded as %s" % (HOSTNAME, DOMAIN, page)