Skip to content

Commit

Permalink
Simple script to update AWS Route 53 from a dynamic ip host
Browse files Browse the repository at this point in the history
I run this in a cron job to update my home VPN server
  • Loading branch information
jideshv committed Nov 17, 2015
0 parents commit 97797de
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions route53me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import boto3
import requests
import re
import time

# Replace below with correct hosted zone id, host name, and desired TTL
hostedZoneId = 'ZK8XMWWB*****'
hostName = 'host.dyn.example.com'
ttl = 60

# Any ip lookup service that returns just the ip address as text
ipifyEndpoint = 'https://api.ipify.org'

validIpRegex = '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'

thisPublicIp = requests.get(ipifyEndpoint).text

validIpPattern = re.compile(validIpRegex)

validIpMatch = validIpPattern.match(thisPublicIp)

if validIpMatch == None:
# Not a valid ip address
exit('Invalid IP Address: ' + thisPulbicIp)

route53 = boto3.client('route53')

route53.change_resource_record_sets(
HostedZoneId = hostedZoneId,
ChangeBatch = {
'Comment' : 'Last updated by route53me.py at ' % time.gmtime(),
'Changes' : [
{
'Action' : 'UPSERT',
'ResourceRecordSet' :
{
'Name' : hostName,
'Type' : 'A',
'TTL' : ttl,
'ResourceRecords' :
[
{
'Value' : thisPublicIp
},
]
}
},
]
}
)

print ('Updated to ' + thisPublicIp)


0 comments on commit 97797de

Please sign in to comment.