use of software.amazon.awssdk.services.cloudfront.model.CloudFrontException 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);
}
}
use of software.amazon.awssdk.services.cloudfront.model.CloudFrontException in project aws-doc-sdk-examples by awsdocs.
the class DeleteFunction method deleteSpecificFunction.
// snippet-start:[cloudfront.java2.del_function.main]
public static void deleteSpecificFunction(CloudFrontClient cloudFrontClient, String functionName, String ifMatchVal) {
try {
DeleteFunctionRequest functionRequest = DeleteFunctionRequest.builder().name(functionName).ifMatch(ifMatchVal).build();
cloudFrontClient.deleteFunction(functionRequest);
System.out.println(functionName + " was successfully deleted.");
} catch (CloudFrontException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.cloudfront.model.CloudFrontException in project aws-doc-sdk-examples by awsdocs.
the class GetDistrubutions method getCFDistrubutions.
// snippet-start:[cloudfront.java2.dis.main]
public static void getCFDistrubutions(CloudFrontClient cloudFrontClient) {
try {
ListDistributionsResponse response = cloudFrontClient.listDistributions();
DistributionList list = response.distributionList();
List<DistributionSummary> dists = list.items();
for (DistributionSummary dist : dists) {
System.out.println("The Distribution ARN is " + dist.arn());
}
} catch (CloudFrontException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.cloudfront.model.CloudFrontException in project aws-doc-sdk-examples by awsdocs.
the class CreateFunction method createNewFunction.
// snippet-start:[cloudfront.java2.function.main]
public static String createNewFunction(CloudFrontClient cloudFrontClient, String functionName, String filePath) {
try {
InputStream is = new FileInputStream(filePath);
SdkBytes functionCode = SdkBytes.fromInputStream(is);
FunctionConfig config = FunctionConfig.builder().comment("Created by using the CloudFront Java API").runtime(FunctionRuntime.CLOUDFRONT_JS_1_0).build();
CreateFunctionRequest functionRequest = CreateFunctionRequest.builder().name(functionName).functionCode(functionCode).functionConfig(config).build();
CreateFunctionResponse response = cloudFrontClient.createFunction(functionRequest);
return response.functionSummary().functionMetadata().functionARN();
} catch (CloudFrontException | FileNotFoundException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.cloudfront.model.CloudFrontException in project aws-doc-sdk-examples by awsdocs.
the class DescribeFunction method describeSinFunction.
// snippet-start:[cloudfront.java2.des_function.main]
public static String describeSinFunction(CloudFrontClient cloudFrontClient, String functionName) {
try {
DescribeFunctionRequest functionRequest = DescribeFunctionRequest.builder().name(functionName).stage(FunctionStage.DEVELOPMENT).build();
DescribeFunctionResponse functionResponse = cloudFrontClient.describeFunction(functionRequest);
return functionResponse.eTag();
} catch (CloudFrontException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
Aggregations