Search in sources :

Example 1 with CreateFunctionRequest

use of software.amazon.awssdk.services.cloudfront.model.CreateFunctionRequest 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)

Aggregations

FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 CloudFrontException (software.amazon.awssdk.services.cloudfront.model.CloudFrontException)1 CreateFunctionRequest (software.amazon.awssdk.services.cloudfront.model.CreateFunctionRequest)1 CreateFunctionResponse (software.amazon.awssdk.services.cloudfront.model.CreateFunctionResponse)1 FunctionConfig (software.amazon.awssdk.services.cloudfront.model.FunctionConfig)1