Skip to content

Instantly share code, notes, and snippets.

@allieus
Last active April 8, 2019 14:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save allieus/4f21421ad7553043de06f3f0e54690cc to your computer and use it in GitHub Desktop.
Save allieus/4f21421ad7553043de06f3f0e54690cc to your computer and use it in GitHub Desktop.
Route 53 에 내 도메인 정보 반영하기 (Dynamic DNS 로 활용하기)
# -*- 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