首页 > 解决方案 > Python boto3 route53

问题描述

我正在尝试定义一个包含 3 个条目的 NS 记录,但我找不到正确的方法。无法分配正确的有效值类型。

client = boto3.client('route53')
cluster_name="myserver.com"
for x in range(1, 4):
    node = "node" + str(x) + "." + cluster_name
    print(node)
    response = client.change_resource_record_sets(
        HostedZoneId='Z3Q8SD6RN2TO8XY1XXX',
        ChangeBatch={
            'Comment': '',
            'Changes': [
                {
                    'Action': 'UPSERT',
                    'ResourceRecordSet': {
                        'Name': node,
                        'Type': 'NS',
                        'TTL': 300,
                        'ResourceRecords': [
                            {
                                'Value': first node,
                                'Value': second_node,
                                'Value': third_node,
                            },
                        ],
                    }
                },
            ]
        }
    )

标签: boto3amazon-route53

解决方案


ResourceRecord需要是具有语法的对象列表{"Value": "entry"}

总而言之,它应该是这样的:

response = client.change_resource_record_sets(
        HostedZoneId='Z3Q8SD6RN2TO8XY1XXX',
        ChangeBatch={
            'Comment': '',
            'Changes': [
                {
                    'Action': 'UPSERT',
                    'ResourceRecordSet': {
                        'Name': node,
                        'Type': 'NS',
                        'TTL': 300,
                        'ResourceRecords': [
                            {
                                'Value': first node
                            },{
                                'Value': second_node
                            },{
                                'Value': third_node,
                            }
                        ],
                    }
                },
            ]
        }
    )

查看官方文档:https ://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/route53.html#Route53.Client.change_resource_record_sets


推荐阅读