I'm trying update/create a number of DNS records. I've limited it to creating one for testing purposes, here is the format of the script I'm using:
#!/usr/bin/env python3
import boto3
import botocore
client = boto3.client('route53')
zone_id = '/hostedzone/ZONEID'
try:
response = client.change_resource_record_sets(
HostedZoneId=zone_id,
ChangeBatch={
'Changes': [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': 'www.example.com',
'ResourceRecords': [
{
'Value': '10.0.0.1'
}
],
'Type': 'A'
}
}
]
}
)
print(response)
except botocore.exceptions.ClientError as e:
print(e)
I am certain that I'm using the correct HostedZoneId property (the response is the same whether or not I prefix with /hostedzone or not). I am also certain I am using a fully qualified domain for the Name property of the ResourceRecordSet.
I am using Python 3.5.1 and the latest pip3 install of boto3.
The error produced when running the code above as described is An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request.
It looks like the missing TTL, which is conditionally required based on the docs, is causing the error from Route53's side. I did something like this to get it working:
import boto3
client = boto3.client('route53')
zone_id = '/hostedzone/ZONEID'
boto3.set_stream_logger('botocore')
response = client.change_resource_record_sets(
HostedZoneId=zone_id,
ChangeBatch={
'Changes': [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': 'www.example.com',
'ResourceRecords': [
{
'Value': '10.0.0.1'
}
],
'Type': 'A',
'TTL': 900
}
}
]
}
)
I think the error message could be improved here though. Unfortunately, there is not much we can do from the boto3 side because the error is coming from route53. I would recommend pinging the developer forums to see if this can get updated.
Hi,
Try to add "Region" [Edit] and "TTL" to your ResourceRecordSet.
Having the following worked for me:
HostedZoneId='Z3*****',
ChangeBatch={
'Comment': 'comment',
'Changes': [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': 'z.y.x.test',
'Type': 'A',
'SetIdentifier': 'blabla',
'TTL': 300,
'Region': 'eu-central-1',
'ResourceRecords': [
{
'Value': '10.0.0.1'
},
],
}
},
]
}
)
Closing due to inactivity.
Still getting the issue.
File "/root/PycharmProjects/untitled/mayur-Route53.py", line 44, in
'EvaluateTargetHealth': False
File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 251, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 537, in _make_api_call
raise ClientError(parsed_response, operation_name)
resolved
@ankitkl - how did you resolve this issue?
@merps : Here is my code. Hope this will helps you
```#Maintance Page Up script!!
__author__ = 'ankit'
import boto3
import boto3
client = boto3.client('route53')
response = client.get_hosted_zone(
Id='xxxxxxxxxxxxx'
)
print (response['HostedZone']['Name'])
response1 = client.list_resource_record_sets(
HostedZoneId='Z28KV31ZLUWCGH',
StartRecordName=response['HostedZone']['Name'],
StartRecordType='A',
MaxItems='1000'
)
#if i['Name'] == 'wikirealty.com.':
#print (i)
response2 = client.change_resource_record_sets(
HostedZoneId='xxxxxxxxx',
ChangeBatch={
'Comment': 'changetheweight',
'Changes': [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': 'testing.internal.',
'Type': 'A',
'SetIdentifier': 'Second',
'Weight': 0,
#'TTL': 300,
#'Region': 'us-west-1',
'AliasTarget': {
'HostedZoneId': 'xxxxxxxxxxxxx',
'DNSName': 'xxxxxxxxxxxxxxxx.elb.amazonaws.com.',
'EvaluateTargetHealth': False
}
}},]})
response3 = client.change_resource_record_sets(
HostedZoneId='xxxxxxxxxxxx',
ChangeBatch={
'Comment': 'change the Weight of the testing-zxy record',
'Changes': [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': 'testing.internal.',
'Type': 'A',
'SetIdentifier': 'First',
'Weight': 255,
#'TTL': 300,
#'Region': 'us-west-1',
'AliasTarget': {
'HostedZoneId': 'xxxxxxxxxx',
'DNSName': 'xxxxxxxxxxxxxxxxxxxxxxxx.elb.amazonaws.com.',
'EvaluateTargetHealth': False
}
}},]})
print (response2,response3)```
Most helpful comment
It looks like the missing
TTL, which is conditionally required based on the docs, is causing the error from Route53's side. I did something like this to get it working:I think the error message could be improved here though. Unfortunately, there is not much we can do from the boto3 side because the error is coming from route53. I would recommend pinging the developer forums to see if this can get updated.