Last active
July 10, 2017 20:38
-
-
Save nip3o/c68ae044d97a7b42f0fb7f2103d8fa66 to your computer and use it in GitHub Desktop.
Yet another DynDNS script for AWS Route53
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
#!/usr/bin/python | |
import re | |
import boto3 | |
import requests | |
ZONE_ID = 'ABCDEFGH123545' | |
DOMAIN_NAME = 'whatever.com' | |
new_ip = re.sub('[\s+]', '', requests.get('http://checkip.amazonaws.com').text) | |
# Make some kind of sanity checks before hitting the AWS API. | |
assert re.match(r'^\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b$', new_ip) | |
assert ZONE_ID | |
assert DOMAIN_NAME | |
route53 = boto3.client('route53') | |
route53.change_resource_record_sets( | |
HostedZoneId=ZONE_ID, | |
ChangeBatch={ | |
'Changes': [{ | |
'Action': 'UPSERT', | |
'ResourceRecordSet': { | |
'Name': DOMAIN_NAME, | |
'Type': 'A', | |
'TTL': 300, | |
'ResourceRecords': [{ | |
'Value': new_ip, | |
}] | |
} | |
}] | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment