-
-
Save inureyes/05c83e02d4657d53c04ce908ca36718a to your computer and use it in GitHub Desktop.
Route 53 에 내 도메인 정보 반영하기 (Dynamic DNS 로 활용하기)
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
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
import os | |
from boto.route53 import connect_to_region | |
from boto.route53.record import ResourceRecordSets | |
def apply(domain, ip, ttl, region, access_key=None, secret_key=None): | |
if access_key: | |
os.environ.setdefault('AWS_ACCESS_KEY_ID', access_key) | |
if secret_key: | |
os.environ.setdefault('AWS_SECRET_ACCESS_KEY', secret_key) | |
conn = connect_to_region(region) | |
zone_domain = '.'.join(domain.split('.')[-2:]) + '.' | |
zone = conn.get_zone(zone_domain) | |
change_set = ResourceRecordSets(conn, zone.id) | |
if not domain.endswith('.'): | |
domain += '.' | |
change = change_set.add_change('UPSERT', domain, type='A', ttl=ttl) | |
change.add_value(ip) | |
change_set.commit() | |
if __name__ == '__main__': | |
# 세팅을 원하는 도메인을 넣어주세요. | |
# 본 도메인의 zone 세팅이 되어있어야 합니다. | |
domain = 'askdjango.domain.net' | |
# 세팅을 원하는 IP를 넣어주세요. | |
ip = '100.100.100.100' | |
ttl = 300 # Time To Live, 300초 | |
apply(domain, ip, ttl, 'ap-northeast-1') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment