Adam Porad
Adam Porad

Reputation: 14471

InvalidInput error when trying to Create or Upsert a Route53 A record

When I run this boto3 to create or upsert an A record, I get the error:

File "./metakube.py", line 523, in post_create self.route53_update_alias_record(self.fugu_editor_external_dns, fugu_elb_identifier)

File "./metakube.py", line 508, in route53_update_alias_record 'EvaluateTargetHealth': False

File "/home/pairaccount/.virtualenvs/fugui-devops/local/lib/python2.7/site-packages/botocore/client.py", line 236, in _api_call return self._make_api_call(operation_name, kwargs)

File "/home/pairaccount/.virtualenvs/fugui-devops/local/lib/python2.7/site-packages/botocore/client.py", line 500, in _make_api_call raise ClientError(parsed_response, operation_name)

botocore.exceptions.ClientError: An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request

Based on the boto3 documentation this looks like the correct input. We've tried a few different variations too, but we get this error when we try to Create or Upsert an A record with this method below. We have a similar method that calls change_resource_record_sets to delete an A record and it works fine.

Any ideas on what needs to be corrected?

def route53_update_alias_record(self, external_dns_name, load_balancer_identifier):
    route53_client = boto3.client('route53')
    hosted_zone_id = self.get_hosted_zone_id(route53_client)

    response = route53_client.change_resource_record_sets(
        HostedZoneId=hosted_zone_id,
        ChangeBatch={
            'Comment': 'upsert alias record',
            'Changes': [
                {
                    'Action': 'UPSERT',
                    'ResourceRecordSet': {
                        'Name': external_dns_name,
                        'Type': 'A',
                        'Region': 'us-east-1',
                        'AliasTarget': {
                            'DNSName': load_balancer_identifier,
                            'HostedZoneId': 'Z3DZXE0Q79N41H',
                            'EvaluateTargetHealth': False
                        }
                    }
                }
            ]
        }
    )
    self.logger.info("Delete route53 alias {} response: {}".format(external_dns_name, response))

Upvotes: 6

Views: 1384

Answers (1)

liujiapeng
liujiapeng

Reputation: 46

you need TTL

like :

response = client.change_resource_record_sets(
        HostedZoneId=hostedzoneid,
        ChangeBatch={
            'Comment': 'add record',
            'Changes': [
                {
                    'Action': 'UPSERT',
                    'ResourceRecordSet': {
                        'Name': name,
                        'Type': 'A',
                        'TTL': ttl,
                        'ResourceRecords': [
                            {
                                'Value': value
                            }
                        ]
                    }
                }
            ]
        }
    )

Upvotes: 2

Related Questions