我无法更新现有的AWS Cloud Front CNAME

时间:2019-07-03 11:53:03

标签: java amazon-web-services spring-boot amazon-cloudfront

我正在尝试以编程方式为AWS Cloud Front中的现有发行版添加CNAME。

我尝试了以下代码,但未给出任何结果。如果有人知道如何以编程方式进行操作。请友善提及。谢谢

      AmazonCloudFront cloudFront = AmazonCloudFrontAsyncClientBuilder.standard()
                        .withRegion(Regions.AP_EAST_1)
                        .withCredentials(new AWSStaticCredentialsProvider(
                                new BasicAWSCredentials(route53Manager.getAccessKey(), route53Manager.getSecretKey())))
                        .build();

                GetDistributionConfigResult result = cloudFront.getDistributionConfig(
                        new GetDistributionConfigRequest("E1EJBNNYJZ6G34"));

                Aliases aliases = new Aliases()
                        .withItems(subDomain)
                        .withQuantity(1);
                DistributionConfig config = result.getDistributionConfig()
                        .withEnabled(true)
                        .withAliases(aliases);

1 个答案:

答案 0 :(得分:0)

您似乎缺少更新分发代码和一些其他东西。请参见以下代码:

AmazonCloudFront cloudFront = AmazonCloudFrontAsyncClientBuilder.standard()
    .withRegion(Regions.AP_EAST_1)
    .withCredentials(new AWSStaticCredentialsProvider(
        new BasicAWSCredentials(route53Manager.getAccessKey(), route53Manager.getSecretKey())))
    .build();

//create the request
GetDistributionConfigRequest distributionConfigRequest = new GetDistributionConfigRequest("E1EJBNNYJZ6G34");

//submit the request and get the resulting config
GetDistributionConfigResult distributionConfigResult = cloudFront.getDistributionConfig(distributionConfigRequest);

Aliases aliases = new Aliases()
    .withItems(subDomain)
    .withQuantity(1);

DistributionConfig config = distributionConfigResult.getDistributionConfig()
    .withEnabled(true)
    .withAliases(aliases);

//create the update request
UpdateDistributionRequest updateDistributionRequest = new UpdateDistributionRequest(config, distributionConfigRequest.getId(), distributionConfigResult.getETag());

//submit the request to update the config
UpdateDistributionResult updateDistributionResult = cloudfront.updateDistribution(updateDistributionRequest);

//print output of result to console
System.out.println(updateDistributionResult);