List of usage examples for com.amazonaws.services.cloudfront AmazonCloudFrontClient AmazonCloudFrontClient
AmazonCloudFrontClient(AwsSyncClientParams clientParams)
From source file:com.kpbird.aws.Main.java
public void createCloudFront() { try {//from w w w. ja v a2 s . c om 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); } }
From source file:org.duracloud.s3storage.S3ProviderUtil.java
License:Apache License
private static AmazonCloudFrontClient newAmazonCloudFrontClient(String accessKey, String secretKey) { BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); try {//from w ww. j a v a2 s. c om return new AmazonCloudFrontClient(awsCredentials); } catch (AmazonServiceException e) { String err = "Could not create connection to Amazon CloudFront " + "due to error: " + e.getMessage(); throw new StorageException(err, e, RETRY); } }