Search in sources :

Example 1 with CreateFunctionRequest

use of software.amazon.awssdk.services.lambda.model.CreateFunctionRequest in project aws-doc-sdk-examples by awsdocs.

the class CreateFunction method createLambdaFunction.

// snippet-start:[lambda.java2.create.main]
public static void createLambdaFunction(LambdaClient awsLambda, String functionName, String filePath, String role, String handler) {
    try {
        InputStream is = new FileInputStream(filePath);
        SdkBytes fileToUpload = SdkBytes.fromInputStream(is);
        FunctionCode code = FunctionCode.builder().zipFile(fileToUpload).build();
        CreateFunctionRequest functionRequest = CreateFunctionRequest.builder().functionName(functionName).description("Created by the Lambda Java API").code(code).handler(handler).runtime(Runtime.JAVA8).role(role).build();
        CreateFunctionResponse functionResponse = awsLambda.createFunction(functionRequest);
        System.out.println("The function ARN is " + functionResponse.functionArn());
    } catch (LambdaException | FileNotFoundException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : CreateFunctionResponse(software.amazon.awssdk.services.lambda.model.CreateFunctionResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) CreateFunctionRequest(software.amazon.awssdk.services.lambda.model.CreateFunctionRequest) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FunctionCode(software.amazon.awssdk.services.lambda.model.FunctionCode) FileNotFoundException(java.io.FileNotFoundException) LambdaException(software.amazon.awssdk.services.lambda.model.LambdaException) 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 CreateFunctionRequest (software.amazon.awssdk.services.lambda.model.CreateFunctionRequest)1 CreateFunctionResponse (software.amazon.awssdk.services.lambda.model.CreateFunctionResponse)1 FunctionCode (software.amazon.awssdk.services.lambda.model.FunctionCode)1 LambdaException (software.amazon.awssdk.services.lambda.model.LambdaException)1