Skip to content

Instantly share code, notes, and snippets.

@nip3o
Last active July 10, 2017 20:38
Show Gist options
  • Save nip3o/c68ae044d97a7b42f0fb7f2103d8fa66 to your computer and use it in GitHub Desktop.
Save nip3o/c68ae044d97a7b42f0fb7f2103d8fa66 to your computer and use it in GitHub Desktop.
Yet another DynDNS script for AWS Route53
#!/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