use of software.amazon.awssdk.services.lambda.model.CreateFunctionResponse 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);
}
}
Aggregations