AWS Python SDK | 路线53 - 删除资源记录

sed*_*rep 4 python dns amazon-web-services amazon-route53 aws-sdk

如何删除Route 53中的DNS记录?我按照文档,但我仍然无法使其工作.我不知道我在这里遗失了什么.

根据文档:

DELETE:删除具有Name,Type,SetIdentifier(用于延迟,加权,地理位置和故障转移资源记录集)和TTL(别名资源记录集除外)的现有资源记录集,其中TTL由您要将DNS查询路由到的AWS资源.

但我总是得到这个错误:

Traceback (most recent call last):                                                                                                                                      
  File "./test.py", line 37, in <module>                                                                                                                                
    main()                                                                                                                                                              
  File "./test.py", line 34, in main                                                                                                                                    
    print(del_record())                                                                                                                                                 
  File "./test.py", line 23, in del_record                                                                                                                              
    'TTL': 300                                                                                                                                                          
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/botocore/client.py", line 251, in _api_call                                       
    return self._make_api_call(operation_name, kwargs)                                                                                                                  
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/botocore/client.py", line 537, in _make_api_call                                  
    raise ClientError(parsed_response, operation_name)                                                                                                                  
botocore.exceptions.ClientError: An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request 
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#!/usr/bin/env python3


import boto3

r53 = boto3.client('route53')
zone_id = 'ABCDEFGHIJKLMNO'
record = 'me.domain.com'
r_type = 'CNAME'
r_val = 'google.com'


def del_record():
    response = r53.change_resource_record_sets(
        HostedZoneId=zone_id,
        ChangeBatch={
            'Changes': [
                {
                    'Action': 'DELETE',
                    'ResourceRecordSet': {
                        'Name': record,
                        'Type': r_type,
                        'TTL': 300
                    }
                }
            ]
        }
    )

    return response


def main():
    print(del_record())

if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

Dan*_*ott 7

您需要在ResourceRecordSet中使用嵌套的"ResourceRecords"数组,该数组具有记录的当前"目标"值.

    HostedZoneId=zone_id,
    ChangeBatch={
        'Changes': [
            {
                'Action': 'DELETE',
                'ResourceRecordSet': {
                    'Name': record,
                    'Type': r_type,
                    'TTL': 300,
                    'ResourceRecords': [
                        {
                            'Value': target
                        }
                    ]
                }
            }
        ]
    }
Run Code Online (Sandbox Code Playgroud)

  • 我很伤心他们改变了这个功能.回过头来,您可以根据"名称"删除记录.现在你必须在执行删除之前进行大量的查找,因为你也需要Value,TTL和Type. (7认同)