Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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))
like image 874
Adam Porad Avatar asked Apr 08 '16 00:04

Adam Porad


People also ask

How do you create a record on Route 53?

On the Hosted zones page, choose the name of the hosted zone that you want to create records in. Choose Create record. Choose and define the applicable routing policy and values.

What is Upsert in route53?

UPSERT : If a resource set exists Route 53 updates it with the values in the request.

How long does it take for Route 53 record to propagate?

Amazon Route 53 is designed to propagate updates you make to your DNS records to its world-wide network of authoritative DNS servers within 60 seconds under normal conditions.

Does route53 support MX records?

Does Route 53 support MX Records? It supports CNAME records, but not MX records.


1 Answers

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
                            }
                        ]
                    }
                }
            ]
        }
    )
like image 76
liujiapeng Avatar answered Sep 24 '22 18:09

liujiapeng