Boto - 如何从route53删除记录集 - 删除资源记录集但未找到

时间:2012-07-11 01:43:22

标签: python boto amazon-route53

我使用以下命令删除route53记录。我没有收到错误消息。

conn = Route53Connection(aws_access_key_id, aws_secret_access_key)
changes = ResourceRecordSets(conn, zone_id)
change = changes.add_change("DELETE",sub_domain, "A", 60,weight=weight,identifier=identifier)
change.add_value(ip_old)
changes.commit()

所有必填字段都存在且匹配..权重,标识符, ttl = 60等。\

e.g。

test.com. A 111.111.111.111 60 1 id1
test.com. A 111.111.111.222 60 1 id2

我想删除111.111.111.222和记录集。

那么,删除记录集的正确方法是什么?

对于记录集,我将有多个值可区分 通过唯一标识符。当一个IP地址变为活动时我想要 从route53中删除。我正在使用一个可怜的勒芒负载平衡。

Here is the meta of the record  want to delete.  
{'alias_dns_name': None,
  'alias_hosted_zone_id': None,
  'identifier': u'15754-1',
  'name': u'hui.com.',
  'resource_records': [u'103.4.xxx.xxx'],
  'ttl': u'60',
  'type': u'A',
  'weight': u'1'}



Traceback (most recent call last):
  File "/home/ubuntu/workspace/rtbopsConfig/classes/redis_ha.py", line 353, in <module>
    deleteRedisSubDomains(aws_access_key_id, aws_secret_access_key,platform=platform,sub_domain=sub_domain,redis_domain=redis_domain,zone_id=zone_id,ip_address=ip_address,weight=1,identifier=identifier)
  File "/home/ubuntu/workspace/rtbopsConfig/classes/redis_ha.py", line 341, in deleteRedisSubDomains
    changes.commit()
  File "/usr/local/lib/python2.7/dist-packages/boto-2.3.0-py2.7.egg/boto/route53/record.py", line 131, in commit
    return self.connection.change_rrsets(self.hosted_zone_id, self.to_xml())
  File "/usr/local/lib/python2.7/dist-packages/boto-2.3.0-py2.7.egg/boto/route53/connection.py", line 291, in change_rrsets
    body)
boto.route53.exception.DNSServerError: DNSServerError: 400 Bad Request
<?xml version="1.0"?>
<ErrorResponse xmlns="https://route53.amazonaws.com/doc/2011-05-05/"><Error><Type>Sender</Type><Code>InvalidChangeBatch</Code><Message>Tried to delete resource record set hui.com., type A, SetIdentifier 15754-1  but it was not found</Message></Error><RequestId>9972af89-cb69-11e1-803b-7bde5b9c457d</RequestId></ErrorResponse>

由于

3 个答案:

答案 0 :(得分:1)

您确定需要add_change的所有参数吗?

Look at add_change here.

默认参数被赋予该函数,因此您可能通过提供权重和TTL来过度指定。

尝试离开体重和TTL(您可能需要保留标识符)。 This blog提供了删除记录的简单示例:

此外,我无法看到您传递的参数值,但确保其完整性并尝试包含“。”在子域的末尾

答案 1 :(得分:1)

我尝试了类似的例子,并且必须指定包括weight和ttl在内的所有字段才能成功删除。 (通过保持默认,它不起作用)。无法通过加权DNS记录产生原始问题并明确传递ttl。

答案 2 :(得分:0)

boto3

import boto3

client = boto3.connect('route53')
hosted_zone_id = "G5LEP7LWYS8WL2"

response = client.change_resource_record_sets(
    ChangeBatch={
        'Changes': [
            {
                'Action': 'DELETE',
                'ResourceRecordSet': {
                    'Name': 'test.example.com',
                    'ResourceRecords': [
                        {
                            'Value': '10.1.1.1',
                        },
                    ],
                    'Type': 'A',
                },
            },
        ]
    },
    HostedZoneId=hosted_zone_id,
)

print(response)

来源:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/route53.html#Route53.Client.change_resource_record_sets

boto

import boto
from boto.route53.record import ResourceRecordSets

conn = boto.connect_route53()

hosted_zone_id = "G5LEP7LWYS8WL2"
record_sets = ResourceRecordSets(conn, hosted_zone_id)

change = record_sets.add_change("DELETE", "test.example.com", "A")
change.add_value("10.1.1.1")

response = record_sets.commit()
print(response)

来源:https://danieljamesscott.org/17-software/development/33-manipulating-aws-route53-entries-using-boto.html