如何解决如何使用 Python 脚本更新所有 ElasticBeanstalk 环境的 A 记录?
我需要更新我的 AWS Route53 托管区域的所有 A 记录(它们当前使用弹性 IP 并且需要是环境的 URL),并且已经尝试使用 boto 脚本来完成此操作(如下)但可以不让它工作。当我运行脚本时,我收到一条错误消息,以“意外的列表元素终止”的形式指示“MalformedInput”:
Traceback (most recent call last):
File "/Users/Orome/Documents/Projects/Web/Sites/tasare/_mwe.py",line 70,in <module>
alias_update()
File "/Users/Orome/Documents/Projects/Web/Sites/tasare/_mwe.py",line 55,in alias_update
records.commit()
File "/Users/Orome/Documents/Projects/Coding/Python/venvs/tasare/lib/python3.9/site-packages/boto/route53/record.py",line 168,in commit
return self.connection.change_rrsets(self.hosted_zone_id,self.to_xml())
File "/Users/Orome/Documents/Projects/Coding/Python/venvs/tasare/lib/python3.9/site-packages/boto/route53/connection.py",line 473,in change_rrsets
raise exception.DNSServerError(response.status,boto.route53.exception.DNSServerError: DNSServerError: 400 Bad Request
<?xml version="1.0"?>
<ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><Error><Type>Sender</Type><Code>MalformedInput</Code><Message>Unexpected list element termination</Message></Error><RequestId>3e79fb18-2231-313-bb7b-ce3489a1e8ab</RequestId></ErrorResponse>
如何使用 Python 脚本更新 ElasticBeanstalk 环境的所有 A 记录?
# pip list shows (among other things)
# boto 2.49.0
# boto3 1.17.76
# botocore 1.20.76
import boto
import boto.beanstalk
import boto.ec2
import boto.route53
# For MWE to work: need to replace with values for which your AWS credentials work
MY_ENV_URL = 'myenv.us-west-2.elasticbeanstalk.com'
MY_ENV = 'myenv'
MY_REGION = 'us-west-2'
HOSTED_DOMAINS = ['mysite1.com','mysite2.org'] # A very long list in the full implementation
def alias_update(region=MY_REGION,ttl=5):
"""Update DNS records to host all application's Route 53 domains at EB environment; use when environment URL chages changes"""
print("Updating A Records for domains hosted by {} to '{}'".format(MY_ENV,MY_ENV_URL))
add_change_args_upsert = {
'action': 'UPSERT','type': 'A','alias_dns_name': MY_ENV_URL,'alias_evaluate_target_health': True
}
for hz in get_app_zones():
print(" Updating {}".format(hz.name[:-1]))
add_change_args_upsert['name'] = hz.name[:-1]
records = hz.get_records()
change = records.add_change(**add_change_args_upsert)
records.commit()
def get_app_zones():
"""Get Route 53 Hosted Zones for this application"""
# This is a bit more complex int the full implementation,but works correctly,as here
r53 = boto.route53.connection.Route53Connection()
hzs = r53.get_zones()
return [hz for hz in hzs if hz.name[:-1] in HOSTED_DOMAINS]
if __name__ == '__main__':
alias_update()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。