Search in sources :

Example 1 with UpdateDistributionRequest

use of software.amazon.awssdk.services.cloudfront.model.UpdateDistributionRequest in project aws-doc-sdk-examples by awsdocs.

the class ModifyDistribution method modDistribution.

// snippet-start:[cloudfront.java2.mod.main]
public static void modDistribution(CloudFrontClient cloudFrontClient, String idVal) {
    try {
        // Get the Distribution to modify.
        GetDistributionRequest disRequest = GetDistributionRequest.builder().id(idVal).build();
        GetDistributionResponse response = cloudFrontClient.getDistribution(disRequest);
        Distribution disObject = response.distribution();
        DistributionConfig config = disObject.distributionConfig();
        // Create a new  DistributionConfig object and add new values to comment and aliases
        DistributionConfig config1 = DistributionConfig.builder().aliases(// You can pass in new values here
        config.aliases()).comment("New Comment").cacheBehaviors(config.cacheBehaviors()).priceClass(config.priceClass()).defaultCacheBehavior(config.defaultCacheBehavior()).enabled(config.enabled()).callerReference(config.callerReference()).logging(config.logging()).originGroups(config.originGroups()).origins(config.origins()).restrictions(config.restrictions()).defaultRootObject(config.defaultRootObject()).webACLId(config.webACLId()).httpVersion(config.httpVersion()).viewerCertificate(config.viewerCertificate()).customErrorResponses(config.customErrorResponses()).build();
        UpdateDistributionRequest updateDistributionRequest = UpdateDistributionRequest.builder().distributionConfig(config1).id(disObject.id()).ifMatch(response.eTag()).build();
        cloudFrontClient.updateDistribution(updateDistributionRequest);
    } catch (CloudFrontException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DistributionConfig(software.amazon.awssdk.services.cloudfront.model.DistributionConfig) UpdateDistributionRequest(software.amazon.awssdk.services.cloudfront.model.UpdateDistributionRequest) GetDistributionResponse(software.amazon.awssdk.services.cloudfront.model.GetDistributionResponse) Distribution(software.amazon.awssdk.services.cloudfront.model.Distribution) CloudFrontException(software.amazon.awssdk.services.cloudfront.model.CloudFrontException) GetDistributionRequest(software.amazon.awssdk.services.cloudfront.model.GetDistributionRequest)

Aggregations

CloudFrontException (software.amazon.awssdk.services.cloudfront.model.CloudFrontException)1 Distribution (software.amazon.awssdk.services.cloudfront.model.Distribution)1 DistributionConfig (software.amazon.awssdk.services.cloudfront.model.DistributionConfig)1 GetDistributionRequest (software.amazon.awssdk.services.cloudfront.model.GetDistributionRequest)1 GetDistributionResponse (software.amazon.awssdk.services.cloudfront.model.GetDistributionResponse)1 UpdateDistributionRequest (software.amazon.awssdk.services.cloudfront.model.UpdateDistributionRequest)1