Example usage for com.amazonaws.services.route53 AmazonRoute53 createHostedZone

List of usage examples for com.amazonaws.services.route53 AmazonRoute53 createHostedZone

Introduction

In this page you can find the example usage for com.amazonaws.services.route53 AmazonRoute53 createHostedZone.

Prototype

CreateHostedZoneResult createHostedZone(CreateHostedZoneRequest createHostedZoneRequest);

Source Link

Document

Creates a new public or private hosted zone.

Usage

From source file:jp.classmethod.aws.gradle.route53.CreateHostedZoneTask.java

License:Apache License

@TaskAction
public void createHostedZone() throws UnknownHostException {
    // to enable conventionMappings feature
    String hostedZoneName = getHostedZoneName();
    String callerReference = getCallerReference() != null ? getCallerReference()
            : InetAddress.getLocalHost().getHostName();
    String comment = getComment();

    AmazonRoute53PluginExtension ext = getProject().getExtensions()
            .getByType(AmazonRoute53PluginExtension.class);
    AmazonRoute53 route53 = ext.getClient();

    getLogger().info("callerRef = {}", callerReference);

    CreateHostedZoneRequest req = new CreateHostedZoneRequest().withName(hostedZoneName)
            .withCallerReference(callerReference);
    if (comment != null) {
        req.setHostedZoneConfig(new HostedZoneConfig().withComment(comment));
    }//from  w  w  w.j a v a 2 s  .  co m

    try {
        createHostedZoneResult = route53.createHostedZone(req);
        nameServers = createHostedZoneResult.getDelegationSet().getNameServers();
        hostedZoneId = createHostedZoneResult.getHostedZone().getId();
        getLogger().info("HostedZone {} ({} - {})  is created.", hostedZoneId, hostedZoneName, callerReference);
        nameServers.forEach(it -> {
            getLogger().info("  NS {}", it);
        });
    } catch (HostedZoneAlreadyExistsException e) {
        getLogger().error("HostedZone {} - {} is already created.", hostedZoneName, callerReference);
    }
}