Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible using the Java AWS API to update a Route53 record?

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

like image 797
Craig S. Dickson Avatar asked Dec 28 '22 02:12

Craig S. Dickson


1 Answers

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.

like image 79
Pedro Madrid Avatar answered May 11 '23 09:05

Pedro Madrid