jeudi 26 février 2015

How do I change the nameservers for my AWS Route53 Registered Domain using boto?

I'm unable to use the AWS boto API to change name servers for my AWS Route53 Registered Domain. In the following Python code, I get



boto.exception.JSONResponseError: JSONResponseError: 400 Bad Request
{u'Message': u'Expected null', u'__type': u'SerializationException'}


even though I'm using the API as documented, passing a list of strings such as



['ns-705.awsdns-21.net', 'ns-1401.awsdns-24.org', 'ns-1107.awsdns-11.co.uk', 'ns-242.awsdns-75.com']


as the second argument.


How can I change nameservers from Python?





def createhz(domain=None, verbose=False):
"""Create a Hosted Zone for the specified domain and update nameservers for Route53 Registered Domain"""
r53 = boto.route53.connection.Route53Connection()
if r53.get_hosted_zone_by_name(domain + '.'):
print('WARNING: Hosted Zone for {} already exists.'.format(domain))
hz = r53.get_zone(domain + '.')
else:
if verbose:
print('Creating Hosted Zone for {}.'.format(domain))
hz = r53.create_zone(domain + '.')

nameservers = hz.get_nameservers()
if verbose:
print('Hosted Zone has nameservers:')
for ns in nameservers:
print(' {}'.format(ns))

registered_domains = boto.route53.domains.layer1.Route53DomainsConnection()

try:
registered_domains.get_domain_detail(domain)
if verbose:
print('Updating nameservers for Route53 Registered Domain.'.format(domain))
# THE FOLLOWING LINE FAILS
registered_domains.update_domain_nameservers(domain, nameservers)
except Exception as e:
if e.message == 'Domain not found.':
print('WARNING: No Route53 Registered Domain for {}.'.format(domain))
print('Set the nameservers at your domain registrar to:.'.format(domain))
for ns in nameservers:
print(' {}'.format(ns))
else:
raise e

return





Traceback (most recent call last):
File "manage.py", line 362, in <module>
manager.run()
File "/usr/local/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/usr/local/lib/python2.7/site-packages/flask_script/__init__.py", line 383, in handle
res = handle(*args, **config)
File "/usr/local/lib/python2.7/site-packages/flask_script/commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "manage.py", line 336, in createhz
raise e
boto.exception.JSONResponseError: JSONResponseError: 400 Bad Request
{u'Message': u'Expected null', u'__type': u'SerializationException'}




Aucun commentaire:

Enregistrer un commentaire