python - 如何使用 boto 更改我的 AWS Route53 注册域的名称服务器?

标签 python amazon-web-services boto amazon-route53

我无法使用 AWS boto API更改我的 AWS 的名称服务器 Route53注册域名。在下面的Python代码中,我得到

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

即使我正在使用 API as documented ,传递字符串列表,例如

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

作为第二个参数。

如何从 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'}

最佳答案

对 Route53 域功能的支持在 boto 中是相当新的,并且没有很好的文档记录。通过查看服务 API,我发现 update_domain_servers 方法期望 nameservers 参数是以下形式的字典列表:

[{"Name": "ns1.example.com"}, {"Name": "ns2.example.com"}]

还有一个名为 GlueIps 的可选键。听起来这对于您的情况来说不是必要的,但您可以找到更多信息 here

关于python - 如何使用 boto 更改我的 AWS Route53 注册域的名称服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28750641/

相关文章:

Python 多处理 : Process object not callable

javascript - 在 EC2 上为 nodejs express 应用监听对端口 3000 的 HTTPS 请求

amazon-web-services - 如何解决无法找到 AWS Java 应用程序请求目标的有效认证路径?

amazon-web-services - 如何解决 botocore.exceptions.NoCredentialsError : Unable to locate credentials

python - 如何更新 python lib boto?

python - 如何在狮身人面像中制作彩色盒子

python - pip install matplotlib 在 termux (Android) 下不起作用

amazon-web-services - 如何保护私有(private)子网后面的 Erlang 集群

python - Boto SES - send_raw_email() 给多个收件人

python - Matplotlib:为多个 twinx() 轴上色