question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

route53.change_resource_record_sets produces InvalidInput error with valid input

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
kyleknapcommented, May 3, 2016

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.

0reactions
ankitklcommented, Jan 5, 2017

@merps : Here is my code. Hope this will helps you

__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'
)

#for i in response1['ResourceRecordSets']:
#    if 'Weight' in i.keys():
#            print (i)
        #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)```
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot errors when creating Route 53 resource record ...
An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid XML ; cvc-enumeration-valid: Value 'Delete' is ...
Read more >
change-resource-record-sets - Amazon AWS
When you submit a ChangeResourceRecordSets request, Route 53 ... with either CountryCode or SubdivisionCode returns an InvalidInput error.
Read more >
Getting InvalidInput error on changeResourceRecordSets
I've found out that the TTL attribute was missing, after adding that it worked just fine, complete example:
Read more >
Network.AWS.Route53 - Hackage
If you own the domain name and Amazon Route 53 generates this error, ... prefix take care to ensure the correct input format...
Read more >
route53 - Go Packages
func (c *Route53) AssociateVPCWithHostedZone(input ... with either CountryCode or SubdivisionCode // returns an InvalidInput error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found