43 lines
1.4 KiB
Python
Executable File
43 lines
1.4 KiB
Python
Executable File
import json
|
|
import argparse
|
|
from datetime import datetime
|
|
from subprocess import check_call
|
|
from .utils import get_public_ip
|
|
|
|
def run():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('-z', "--hosted-zone", metavar='HOSTED_ZONE_ID', required=True,
|
|
help="Specify the hosted zone id")
|
|
parser.add_argument('-d', "--domain", metavar='DOMAIN_NAME', required=True,
|
|
help="Specify domain name")
|
|
parser.add_argument('-t', "--type", metavar='DNS_TYPE', default='A',
|
|
help="Specify DNS type")
|
|
parser.add_argument('-l', "--ttl", metavar='TTL_S', type=int, default=300,
|
|
help="Specify time-to-live in seconds")
|
|
|
|
args = parser.parse_args()
|
|
|
|
date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
public_ip = get_public_ip()
|
|
params = {
|
|
'Comment': f'Auto update by awsdyndns on {date}',
|
|
'Changes': [
|
|
{
|
|
'Action': 'UPSERT',
|
|
'ResourceRecordSet': {
|
|
'ResourceRecords': [{'Value': public_ip}],
|
|
'Name': args.domain,
|
|
'Type': args.type,
|
|
'TTL': args.ttl
|
|
}
|
|
}
|
|
]
|
|
}
|
|
check_call(['aws', 'route53', 'change-resource-record-sets', '--hosted-zone-id', args.hosted_zone, '--change-batch', json.dumps(params)])
|
|
|
|
if __name__ == "__main__":
|
|
run()
|
|
|
|
|
|
|