title: How to delete an route53 A record without knowledge of the target IP in AWS lambda?
body: <p>It seems that the <a href="http://boto3.readthedocs.io/en/latest/reference/services/route53.html#Route53.Client.change_resource_record_sets" rel="nofollow noreferrer">change_resource_record_sets</a> method requires both the Name (e.g. myhost.mydomain.com) and the target values of the record (e.g. 123.123.123.123) to do an <code>'Action': 'DELETE'</code>, however the target IP is removed from terminated instances, so it seems a full lookup of the resource records requires a full <a href="http://boto3.readthedocs.io/en/latest/reference/services/route53.html#Route53.Client.list_resource_record_sets" rel="nofollow noreferrer">list_resource_record_sets</a> scan to get that information. </p>
  
  <p>Is there a preferred method to get the ip of a terminated instance, or to delete a record without knowing the ip in boto3/aws sdk?</p>
  
  <p><strong>detail</strong>: I have a autoscaling group which maintains 3 instances, and a python lambda that is triggered on termination of an autoscaling instance. During the creation of the instance a route53 A record was created matching the vpc private ip address, like this;</p>
  
  <pre><code>instance_id: i-0bfced710f9c11867
  </code></pre>
  
  <p>creates route53 record:</p>
  
  <pre><code>{'Name': 'webXXX-dev-euwest1-0bfced710f9c11867-mydomain.com.',
   'ResourceRecords': [{'Value': '10.69.98.116'}],
   'TTL': 60,
   'Type': 'A'}
  </code></pre>
  
  <p>However when the instance is terminated, the private and public ipv4 fields of the instance are unset in the lambda event (and on the terminated instance in the console). Therefore in order to use the <a href="http://boto3.readthedocs.io/en/latest/reference/services/route53.html#Route53.Client.change_resource_record_sets" rel="nofollow noreferrer">change_resource_record_sets</a> method, I need to provide the IP address from somewhere else;</p>
  
  <pre><code>def delete_route53(host,ip):
      route53.change_resource_record_sets(
      HostedZoneId=hostedzoneid,
      ChangeBatch={
          'Changes': [
              {
                  'Action': 'DELETE',
                  'ResourceRecordSet': {
                      'Name': host,
                      'Type': 'A',
                      'TTL': 60,
                      'ResourceRecords': [
                          {
                              'Value': ip
                          }
                      ]
                  }
              }
          ]
      }
      )
  </code></pre>
  
  <p>So currently I have to do a lookup of the record in order to delete it;</p>
  
  <pre><code>response = route53.list_resource_record_sets(
      HostedZoneId=hostedzoneid,
      StartRecordType='A',
      StartRecordName=domain,
      MaxItems="10"
  )
  </code></pre>
  
  <p>and a bunch of code to recreate the Name and ResourceRecords for the DELETE action. This seems a bit roundabout, and is slow in the lambda due to remote call (which costs money)</p>
  
  <p>Is there a simpler way to delete that record?</p>