2017-10-05 218 views
0

我试图更新一些CNAME记录使用boto3上Route53托管A资源记录,这里是我的功能:(InvalidChangeBatch)调用ChangeResourceRecordSets操作时 - 使用boto3更新

def change_resource_record(domain, zone_id, hosted_zone_id, balancer_id): 
    print(domain, zone_id, hosted_zone_id, balancer_id) 
    client.change_resource_record_sets(
     HostedZoneId=zone_id, 
     ChangeBatch={ 
      "Comment": "Automatic DNS update", 
      "Changes": [ 
       { 
        "Action": "UPSERT", 
        "ResourceRecordSet": { 
         "Name": domain, 
         "Type": "A", 
         "AliasTarget": { 
          "HostedZoneId": hosted_zone_id, 
          "DNSName": balancer_id, 
          "EvaluateTargetHealth": False 
         } 
        } 
       }, 
      ] 
     } 
    ) 

我得到此错误:

Traceback (most recent call last): 
    File "load_balancer.py", line 138, in <module> 
    get_balancer(domain) 
    File "load_balancer.py", line 135, in get_balancer 
    change_resource_record(domain, zone_id, hosted_zone_id, balancer_id) 
    File "load_balancer.py", line 116, in change_resource_record 
    "EvaluateTargetHealth": False 
    File "C:\Python36\lib\site-packages\botocore\client.py", line 312, in _api_call 
    return self._make_api_call(operation_name, kwargs) 
    File "C:\Python36\lib\site-packages\botocore\client.py", line 601, in _make_api_call 
    raise error_class(parsed_response, operation_name) 
botocore.errorfactory.InvalidChangeBatch: An error occurred (InvalidChangeBatch) when calling the ChangeResourceRecordSets operation: RRSet of type A with DNS name suffix.domain.tld. is not permitted because a conflicting RRSet of type CNAME with the same DNS name already exists in zone domain.tld. 

什么是更新记录的正确方法,我应该删除条目然后重新创建它吗?

任何意见是非常感谢。

回答

0

我在domain有缺少一个右期,所以改变这个解决我的问题:

  "ResourceRecordSet": { 
       "Name": domain + '.', 
       "Type": "A", 
       "AliasTarget": { 
        "HostedZoneId": hosted_zone_id, 
        "DNSName": balancer_id, 
        "EvaluateTargetHealth": False 
       } 
      }