How to delete resource record from route 53 using AWS JAVA SDK

How to delete resource record from route 53 using AWS JAVA SDK

Im newbie in java and trying trying to write code to delete specific record from route 53. so far, I have written following code by referring java doc.

package oe.k8s;

import java.util.ArrayList;
import java.util.List;

import com.amazonaws.services.route53.AmazonRoute53;
import com.amazonaws.services.route53.AmazonRoute53Client;
import com.amazonaws.services.route53.model.*;

public class TestName1 {

    public static void main(String[] args) {

        AmazonRoute53 route53Client = AmazonRoute53Client.builder().withRegion("us-east-1").build();

        listZones(route53Client);
    }

    public static void listZones(AmazonRoute53 route53Client) {
        try {

            ResourceRecordSet rr = new ResourceRecordSet("abc.com", "A");

            Change c = new Change(ChangeAction.DELETE, rr);

            List<Change> cc = new ArrayList<>();
            cc.add(c);

            ChangeBatch cb = new ChangeBatch(cc);

            ChangeResourceRecordSetsRequest ccc = new ChangeResourceRecordSetsRequest("abc123", cb);

            ChangeResourceRecordSetsResult ccres = new ChangeResourceRecordSetsResult();
            System.out.println("hiiiiiii");
            System.out.println(ccres.getChangeInfo());

            ListHostedZonesResult zonesResponse = route53Client.listHostedZones();
            List<HostedZone> checklist = zonesResponse.getHostedZones();
            for (HostedZone check : checklist) {
                DeleteTrafficPolicyInstanceRequest rq = new DeleteTrafficPolicyInstanceRequest();
                System.out.println("id is  " + rq.getId());
                System.out.println("The name is : " + check.getName());
                System.out.println("The resource count is : " + check.getResourceRecordSetCount());

            }

        } catch (AmazonRoute53Exception e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }

}

Issue is, it is not deleting record. code is getting compiled and running properly however nothing is happening. Can anyone suggest where I'm doing wrong?

environment details:

  • JAVA: 17
  • AWS SDK version: 1.x

Answer

The operation to perform the actual delete can't be found in the snippet you shared:

This should help:


ChangeResourceRecordSetsResult ccres = route53Client.changeResourceRecordSets(ccc);

You need to call the client to initiate the DELETE action

route53Client.changeResourceRecordSets

Then you can log the response afterwards.

Enjoyed this article?

Check out more content on our blog or follow us on social media.

Browse more articles