title: AWS Java SDK: updating a Route53 zone record with new RDS instance info
body: <p>Java 8 using the AWS Java SDK here. I have a private hosted zone (PHZ) of, say, <code>myapp.example.com</code> and I have an <code>A</code> record in that zone called <code>db.myapp.example.com</code> which points to an RDS instance.</p>
  <p>I am now writing a Lambda (Java) that will create a new RDS instance, and update the <code>db.myapp.example.com</code> zone record to point to the new RDS instance.</p>
  <p>So far the gist of my code looks like this:</p>
  <pre><code>CreateDBInstanceRequest createDbRequest = getSomehow();
  DBInstance rdsInstance = amazonRDS.createDBInstance(createDbRequest);
  
  ListHostedZonesResult hostedZonesResult = amazonRoute53.listHostedZones();
  Optional&lt;HostedZone&gt; hostedZoneOpt = hostedZonesResult.getHostedZones().stream()
      .filter(zone -&gt; &quot;db.myapp.example.com&quot;.equals(zone.getName())).findFirst();
  if (hostedZoneOpt.isPresent()) {
  
      // TODO: how to update the record so that it points to 'rdsInstance'?
      ResourceRecordSet alias = new ResourceRecordSet(aliasName, &quot;A&quot;);
      
      Change updateAlias = new Change(ChangeAction.UPSERT, alias);
      List&lt;Change&gt; changes = Collections.singletonList(updateAlias);
      ChangeBatch changeBatch = new ChangeBatch(changes);
  
      ChangeResourceRecordSetsRequest changeRecordRequest =
          new ChangeResourceRecordSetsRequest(hostedZoneOpt.get().getId(), changeBatch);
      amazonRoute53.changeResourceRecordSets(changeRecordRequest);
      
  } else {
    // handle
  }
  </code></pre>
  <p>I think this is correct for the most part. However, after <em>scouring</em> the <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/route53/AmazonRoute53.html" rel="nofollow noreferrer">Route53 SDK API docs</a> I cannot for the life of me figure out how/where I configure the <code>alias : ResourceRecordSet</code> instance with the new RDS (<code>rdsInstance</code>) info so that <code>db.myapp.example.com</code> now points to it.</p>
  <p><strong>Any ideas?</strong> Thanks in advance!</p>
  <h3>Update</h3>
  <p>I see there is the concept of <code>TrafficPolicy</code> in Route53 and apparently I can send a JSON document to AWS and configure a traffic policy for my A record, so maybe this is the correct way to go. But looking at the <a href="https://docs.aws.amazon.com/Route53/latest/APIReference/api-policies-traffic-policy-document-format.html" rel="nofollow noreferrer">Traffic Policy document definition</a>, I need to be able to specify an IP address in its <code>Value</code> field, and I don't believe the AWS SDK exposes IP addresses anywhere!</p>