I'm having difficulties trying to add a new Alternative Domain Name (CNAMEs) to an existing CloudFront resource using the AWS SDK for Java v2.x
This is the code snippet I'm using so far:
// First I get the actual resource from AWS
GetDistributionResponse distributionInformation = cloudFrontclient
.getDistribution(GetDistributionRequest.builder().id(input.getDistributionId())
.build());
// Then I extract the part I want to edit
DistributionConfig config = distributionInformation.distribution().distributionConfig();
// so far so good, I'm able to see my data as intended
// The next thing is to try adding the new alias, and of course I can't as that array is Unmodifiable!
// Meaning that I'm always getting an: java.lang.UnsupportedOperationException
config.aliases().items().add(input.getAlternativeDomain());
// If the previous line worked or I find an alternative solution I'm planning to make the following update request
UpdateDistributionRequest updateDistributionRequest = UpdateDistributionRequest
.builder()
.distributionConfig(config)
.build();
cloudFrontclient.updateDistribution(updateDistributionRequest);
I'm kind of lost here, I'm not exactly sure how this is supposed to work.
I'll appreciate any help I can get
Thanks in advance