2016-10-22 54 views
4

如何刪除路由53中的DNS記錄?我跟着documentation但我仍然無法使它工作。我不知道我是否在這裏錯過了一些東西。AWS Python SDK |路由53 - 刪除資源記錄

根據相關文檔:

DELETE : Deletes a existing resource record set that has the specified values for Name , Type , SetIdentifier (for latency, weighted, geolocation, and failover resource record sets), and TTL (except alias resource record sets, for which the TTL is determined by the AWS resource that you're routing DNS queries to).

但我總是收到此錯誤:

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 

這裏是我的代碼:

#!/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() 

回答

5

你需要一個嵌套的 'ResourceRecords' ResourceRecordSet中的數組,該數組具有記錄的當前「目標」值。

HostedZoneId=zone_id, 
    ChangeBatch={ 
     'Changes': [ 
      { 
       'Action': 'DELETE', 
       'ResourceRecordSet': { 
        'Name': record, 
        'Type': r_type, 
        'TTL': 300, 
        'ResourceRecords': [ 
         { 
          'Value': target 
         } 
        ] 
       } 
      } 
     ] 
    } 
+5

我很傷心他們已經改變了這個功能。回頭你可以根據「名稱」刪除記錄。現在,在執行刪除操作之前,您必須進行大量查找,因爲您還需要Value,TTL和Type。 –