Search in sources :

Example 1 with CloudFrontException

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);
    }
}
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)

Example 2 with CloudFrontException

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);
    }
}
Also used : CloudFrontException(software.amazon.awssdk.services.cloudfront.model.CloudFrontException) DeleteFunctionRequest(software.amazon.awssdk.services.cloudfront.model.DeleteFunctionRequest)

Example 3 with CloudFrontException

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);
    }
}
Also used : DistributionSummary(software.amazon.awssdk.services.cloudfront.model.DistributionSummary) CloudFrontException(software.amazon.awssdk.services.cloudfront.model.CloudFrontException) ListDistributionsResponse(software.amazon.awssdk.services.cloudfront.model.ListDistributionsResponse) DistributionList(software.amazon.awssdk.services.cloudfront.model.DistributionList)

Example 4 with CloudFrontException

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 "";
}
Also used : FunctionConfig(software.amazon.awssdk.services.cloudfront.model.FunctionConfig) CreateFunctionResponse(software.amazon.awssdk.services.cloudfront.model.CreateFunctionResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) CreateFunctionRequest(software.amazon.awssdk.services.cloudfront.model.CreateFunctionRequest) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CloudFrontException(software.amazon.awssdk.services.cloudfront.model.CloudFrontException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream)

Example 5 with CloudFrontException

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 "";
}
Also used : DescribeFunctionResponse(software.amazon.awssdk.services.cloudfront.model.DescribeFunctionResponse) CloudFrontException(software.amazon.awssdk.services.cloudfront.model.CloudFrontException) DescribeFunctionRequest(software.amazon.awssdk.services.cloudfront.model.DescribeFunctionRequest)

Aggregations

CloudFrontException (software.amazon.awssdk.services.cloudfront.model.CloudFrontException)5 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 CreateFunctionRequest (software.amazon.awssdk.services.cloudfront.model.CreateFunctionRequest)1 CreateFunctionResponse (software.amazon.awssdk.services.cloudfront.model.CreateFunctionResponse)1 DeleteFunctionRequest (software.amazon.awssdk.services.cloudfront.model.DeleteFunctionRequest)1 DescribeFunctionRequest (software.amazon.awssdk.services.cloudfront.model.DescribeFunctionRequest)1 DescribeFunctionResponse (software.amazon.awssdk.services.cloudfront.model.DescribeFunctionResponse)1 Distribution (software.amazon.awssdk.services.cloudfront.model.Distribution)1 DistributionConfig (software.amazon.awssdk.services.cloudfront.model.DistributionConfig)1 DistributionList (software.amazon.awssdk.services.cloudfront.model.DistributionList)1 DistributionSummary (software.amazon.awssdk.services.cloudfront.model.DistributionSummary)1 FunctionConfig (software.amazon.awssdk.services.cloudfront.model.FunctionConfig)1 GetDistributionRequest (software.amazon.awssdk.services.cloudfront.model.GetDistributionRequest)1 GetDistributionResponse (software.amazon.awssdk.services.cloudfront.model.GetDistributionResponse)1 ListDistributionsResponse (software.amazon.awssdk.services.cloudfront.model.ListDistributionsResponse)1 UpdateDistributionRequest (software.amazon.awssdk.services.cloudfront.model.UpdateDistributionRequest)1