Search in sources :

Example 1 with ChangeResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest in project SimianArmy by Netflix.

the class AWSClient method deleteDNSRecord.

/** {@inheritDoc} */
@Override
public void deleteDNSRecord(String dnsName, String dnsType, String hostedZoneID) {
    Validate.notEmpty(dnsName);
    Validate.notEmpty(dnsType);
    if (dnsType.equals("A") || dnsType.equals("AAAA") || dnsType.equals("CNAME")) {
        LOGGER.info(String.format("Deleting DNS Route 53 record %s", dnsName));
        AmazonRoute53Client route53Client = route53Client();
        // AWS API requires us to query for the record first
        ListResourceRecordSetsRequest listRequest = new ListResourceRecordSetsRequest(hostedZoneID);
        listRequest.setMaxItems("1");
        listRequest.setStartRecordType(dnsType);
        listRequest.setStartRecordName(dnsName);
        ListResourceRecordSetsResult listResult = route53Client.listResourceRecordSets(listRequest);
        if (listResult.getResourceRecordSets().size() < 1) {
            throw new NotFoundException("Could not find Route53 record for " + dnsName + " (" + dnsType + ") in zone " + hostedZoneID);
        } else {
            ResourceRecordSet resourceRecord = listResult.getResourceRecordSets().get(0);
            ArrayList<Change> changeList = new ArrayList<>();
            Change recordChange = new Change(ChangeAction.DELETE, resourceRecord);
            changeList.add(recordChange);
            ChangeBatch recordChangeBatch = new ChangeBatch(changeList);
            ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest(hostedZoneID, recordChangeBatch);
            ChangeResourceRecordSetsResult result = route53Client.changeResourceRecordSets(request);
        }
    } else {
        LOGGER.error("dnsType must be one of 'A', 'AAAA', or 'CNAME'");
    }
}
Also used : NotFoundException(com.netflix.simianarmy.NotFoundException) AmazonRoute53Client(com.amazonaws.services.route53.AmazonRoute53Client)

Example 2 with ChangeResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest in project GNS by MobilityFirst.

the class Route53 method createRecordSetFromHostedZone.

private static void createRecordSetFromHostedZone() {
    List<ResourceRecord> records = new ArrayList<>();
    ResourceRecord record = new ResourceRecord();
    record.setValue("http://www.marksdevserver.com");
    records.add(record);
    ResourceRecordSet recordSet = new ResourceRecordSet();
    recordSet.setName("markstest.domain.com.");
    recordSet.setType(RRType.CNAME);
    recordSet.setTTL(new Long(60));
    recordSet.setResourceRecords(records);
    // Create the Change
    List<Change> changes = new ArrayList<>();
    Change change = new Change();
    change.setAction(ChangeAction.CREATE);
    change.setResourceRecordSet(recordSet);
    changes.add(change);
    // Create a batch and add the change to it
    ChangeBatch batch = new ChangeBatch();
    batch.setChanges(changes);
    // Create a Request and add the batch to it.
    ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest();
    request.setHostedZoneId(HOSTED_ZONE_ID);
    request.setChangeBatch(batch);
    // send the request
    ChangeResourceRecordSetsResult result = route53.changeResourceRecordSets(request);
    System.out.println(result.toString());
}
Also used : ResourceRecordSet(com.amazonaws.services.route53.model.ResourceRecordSet) ChangeBatch(com.amazonaws.services.route53.model.ChangeBatch) ArrayList(java.util.ArrayList) Change(com.amazonaws.services.route53.model.Change) ResourceRecord(com.amazonaws.services.route53.model.ResourceRecord) ChangeResourceRecordSetsRequest(com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest) ChangeResourceRecordSetsResult(com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult)

Example 3 with ChangeResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class Route53Setup method setupResources.

public void setupResources() throws InterruptedException {
    List<Change> changes = buildChangesList(Constants.ROUTE53_PREFIXES);
    if (changes.size() > 0) {
        ChangeBatch changeBatch = new ChangeBatch().withChanges(changes);
        ChangeResourceRecordSetsRequest cReq = new ChangeResourceRecordSetsRequest().withHostedZoneId(hostedZone.getId()).withChangeBatch(changeBatch);
        ChangeResourceRecordSetsResult cRes = route53Client.changeResourceRecordSets(cReq);
        GetChangeRequest gcReq = new GetChangeRequest(cRes.getChangeInfo().getId());
        GetChangeResult gcRes = route53Client.getChange(gcReq);
        // TODO: No real need to wait here, could just exit
        while (!"INSYNC".equals(gcRes.getChangeInfo().getStatus())) {
            Thread.sleep(1000L);
            gcRes = route53Client.getChange(gcReq);
            String s = gcRes.getChangeInfo().getStatus();
        }
    }
}
Also used : ChangeBatch(com.amazonaws.services.route53.model.ChangeBatch) Change(com.amazonaws.services.route53.model.Change) ChangeResourceRecordSetsRequest(com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest) ChangeResourceRecordSetsResult(com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult) GetChangeRequest(com.amazonaws.services.route53.model.GetChangeRequest) GetChangeResult(com.amazonaws.services.route53.model.GetChangeResult)

Aggregations

Change (com.amazonaws.services.route53.model.Change)2 ChangeBatch (com.amazonaws.services.route53.model.ChangeBatch)2 ChangeResourceRecordSetsRequest (com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest)2 ChangeResourceRecordSetsResult (com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult)2 AmazonRoute53Client (com.amazonaws.services.route53.AmazonRoute53Client)1 GetChangeRequest (com.amazonaws.services.route53.model.GetChangeRequest)1 GetChangeResult (com.amazonaws.services.route53.model.GetChangeResult)1 ResourceRecord (com.amazonaws.services.route53.model.ResourceRecord)1 ResourceRecordSet (com.amazonaws.services.route53.model.ResourceRecordSet)1 NotFoundException (com.netflix.simianarmy.NotFoundException)1 ArrayList (java.util.ArrayList)1