I have a hosted domain on AWS Route53. Under that domain I have an 'A' record for a subdomain.
I would like to be able to update the IP address of the 'A' record using the Java API. However, when looking at the setAction
method of the com.amazonaws.services.route53.model.Change
class, it only accepts the CREATE
or DELETE
values. This seems to match the allowed values in the XML message that the Java API sends behind the scenes.
Is there any way to just update the IP address, or do I have to delete the original record and then create it again?
Thanks
It worked for me using this piece of code:
ResourceRecord record = new ResourceRecord(loadBalancer);
List<ResourceRecord> records = new ArrayList<ResourceRecord>();
records.add(record);
ResourceRecordSet recordsSet = new ResourceRecordSet();
recordsSet.setResourceRecords(records);
recordsSet.setType(RRType.CNAME);
recordsSet.setTTL(900L);
recordsSet.setName(subdomain + ".");
Change change = new Change(ChangeAction.CREATE, recordsSet);
List<Change> changes = new ArrayList<Change>();
changes.add(change);
ChangeBatch batch = new ChangeBatch(changes);
ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest();
request.setChangeBatch(batch);
request.setHostedZoneId(hostedZoneId);
ChangeResourceRecordSetsResult result = getRoute53Client().changeResourceRecordSets(request);
System.out.println(result);
Just replace the variables I used with proper data. (subdomain, loadBalancer and hostedZoneId). The method getRoute53Client() returns an instance of the AmazonRoute53Client class from the AWS API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With