I searched for the procedure for using Lambda Layers in Java, but I wrote it down because it was not easy to understand.
Export with layer_print.jar
Print.java
package layer_print;
public class Print {
public static void print() {
System.out.println("print from layer!!");
}
}
Create jar without layer_print.jar → Upload to lambda function
MyLambda.java
package lambda_layer_java;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import layer_print.Print;
public class MyLambda implements RequestHandler<Integer, String> {
@Override
public String handleRequest(Integer in, Context context) {
//lambda layer call
Print.print();
return "success";
}
}
Create java / lib folder locally
Put the jar file to be layer in lib
Convert java folder to zip
Select Layers for lambda in the AWS console. Press Create Layer
Enter your name and description. Select java 8 with a compatible runtime. Upload the created zip file and create a layer
Go to the lambda function that uses layers, select Layers and press Add Layer
Select layer and version to add
Save and complete
that's all.
Recommended Posts