Example usage for com.amazonaws.services.cloudfront.model DistributionConfig withComment

List of usage examples for com.amazonaws.services.cloudfront.model DistributionConfig withComment

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront.model DistributionConfig withComment.

Prototype


public DistributionConfig withComment(String comment) 

Source Link

Document

Any comments you want to include about the distribution.

Usage

From source file:com.kpbird.aws.Main.java

public void createCloudFront() {
    try {//from   ww  w.  java2  s.  c  o m
        log.Info("Create CloudFront Distribution For Download");
        AmazonCloudFrontClient cloudfront = new AmazonCloudFrontClient(credentials);
        cloudfront.setEndpoint(endPoint);
        cloudfront.setRegion(region);

        DistributionConfig dc = new DistributionConfig();
        dc.withCallerReference(System.currentTimeMillis() + "");
        dc.withAliases(new Aliases().withQuantity(0));
        dc.withDefaultRootObject("");
        dc.withOrigins(new Origins()
                .withItems(new Origin().withId(cloudFrontS3Origin)
                        .withDomainName(cloudFrontS3Origin + ".s3.amazonaws.com")
                        .withS3OriginConfig(new S3OriginConfig().withOriginAccessIdentity("")))
                .withQuantity(1));
        dc.withDefaultCacheBehavior(new DefaultCacheBehavior().withTargetOriginId(cloudFrontS3Origin)
                .withForwardedValues(new ForwardedValues().withQueryString(false)
                        .withCookies(new CookiePreference().withForward("none")))
                .withTrustedSigners(new TrustedSigners().withQuantity(0).withEnabled(false))
                .withViewerProtocolPolicy(ViewerProtocolPolicy.AllowAll).withMinTTL(cloudFrontMinTTL));
        dc.withCacheBehaviors(new CacheBehaviors().withQuantity(0));
        dc.withComment(cloudFrontDesc);
        dc.withLogging(
                new LoggingConfig().withEnabled(false).withBucket("").withPrefix("").withIncludeCookies(false));
        dc.withEnabled(true);
        dc.withPriceClass(PriceClass.PriceClass_All);

        CreateDistributionRequest cdr = new CreateDistributionRequest().withDistributionConfig(dc);

        CreateDistributionResult distribution = cloudfront.createDistribution(cdr);

        boolean isWait = true;
        while (isWait) {
            Thread.sleep(5000);
            GetDistributionResult gdr = cloudfront
                    .getDistribution(new GetDistributionRequest(distribution.getDistribution().getId()));
            String status = gdr.getDistribution().getStatus();
            log.Info("Status :" + status);
            if (status.equals("Deployed")) {
                isWait = false;
                log.Info("Domain Name :" + gdr.getDistribution().getDomainName());
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }
}