Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't update DNS record on Route 53 using boto3

I'm trying to get an dynamic DNS updater script working using AWS Route 53, python3 and boto3. It functions as follows:

  1. Retrieve machine IP from an internet service
  2. Retrieve current IP in Route 53 DNS
  3. Check if they match (if so, exit)
  4. Update DNS (replace old IP with current one)

Step 4 is not working. The code for it is below. my_ip contains a string that looks like this: 1.2.3.4. I have tried replacing it with a string directly ("Value": "1.2.3.4") but that didn't fix the error. hosted_zone_id is correct as it was already used to pull the IP address. record_name is "microbug.uk.".

response = client.change_resource_record_sets(
    HostedZoneId=hosted_zone_id,
    ChangeBatch={
        "Comment": "Automatic DNS update",
        "Changes": [
            {
                "Action": "UPSERT",
                "ResourceRecordSet": {
                    "Name": record_name,
                    "Type": "A",
                    "Region": "eu-west-1",
                    "TTL": 180,
                    "ResourceRecords": [
                        {
                            "Value": my_ip
                        },
                    ],
                }
            },
        ]
    }
)

This is the error it throws:

Traceback (most recent call last):
  File "update-dns.py", line 42, in <module>
    "Value": my_ip
  File "/usr/lib/python3.5/site-packages/botocore/client.py", line 278, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/lib/python3.5/site-packages/botocore/client.py", line 572, in _make_api_call
    raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request

Any suggestions? Thanks in advance.

edit:

$ cat ~/.aws/config
[default]
region = eu-west-1
output = json
like image 924
microbug Avatar asked Dec 29 '25 09:12

microbug


1 Answers

I solved the problem. The Region option must only be set for latency-based record sets; commenting it out solved the problem.

like image 135
microbug Avatar answered Dec 30 '25 21:12

microbug



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!