aws / aws-lambda-java-libs

Official mirror for interface definitions and helper classes for Java code running on the AWS Lambda platform.
https://aws.amazon.com/lambda/
Apache License 2.0
520 stars 231 forks source link

GraalVM support for aws-lambda-java-runtime-interface-client #272

Open msailes opened 3 years ago

msailes commented 3 years ago

Developers wanting to adopt the aws-lambda-java-runtime-interface-client for their own projects which use GraalVM native-image find integration difficult. This is because this project does not include the required jni and reflection configuration files.

Developers have to include this configuration in their own projects, which is an additional complexity and burden.

ilopmar commented 3 years ago

We did a few tests in Micronaut sometime ago to use this library and it would be really helpful to include all the configuration in the library.

olegz commented 3 years ago

Spring Cloud Functions has implemented its own polling loop for Custom Runtime (for now). We would like to adopt the AWS one to reduce the amount of code we support and instead colaborate and contribute to single AWS code base. However we would prefer NOT to include the required GraalVM configs in our project and instead see if we can help and suggest code changes on yoru end that would make it GraalVM friendly. As the matter of fact, for the past several months we have been going through this effort in all Spring projects to make our code GraalVM friendly whenever we can (i.e., eliminating certain refection calls, @Autowired annotation etc.). And only when something is absolutely not-refactorable (ragrdless of the reason), then as Mark implied, the required configs should come from the framework.

stejsj commented 2 years ago

Been struggling for a weak or two making graalvm working with the runtime client based on samples on github.

This is very important for jvm targetted language since cold start is a very big problem (giving end users and developers a bad customer experience)

We were actually quite near having to select another language than Scala and that would have been a big pain for us.

We believe in the serverless world and are big fans of AWS services combined with Scala, witch actually try to add the same value to the developer. Do more with less effort and faster and as bonus saving manhours and money in the long run.

Graalvm and native images are a perfect fit for all jvm languages since the jvm wasn't build for short lived processes.

Thank you in advance Steffen

alexanderankin commented 1 year ago

Are there any key developments to link to this thread for newcomers trying to create aws lambda/graalvm projects, to this the newest issue about the topic? I found this from googling my errors, it seems like there is still missing metadata, or it is just not clear where to find the libraries supplying it.

msailes commented 1 year ago

Hi @alexanderankin,

I would start with this sample project and adapt from there.

https://github.com/aws-samples/serverless-graalvm-demo

Thanks,

NikolayMetchev commented 3 weeks ago

does anybody have an update to date jni-config.json?

NikolayMetchev commented 3 weeks ago

I am getting the following error:

Exception in thread "main" java.lang.Error: java.lang.NullPointerException
at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:192)
at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.main(AWSLambda.java:180)
Caused by: java.lang.NullPointerException
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getFieldID(JNIFunctions.java:1274)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetFieldID(JNIFunctions.java:432)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.JNIOnLoadFunctionPointer.invoke(JNILibraryInitializer.java)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.JNILibraryInitializer.callOnLoadFunction(JNILibraryInitializer.java:71)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.JNILibraryInitializer.initialize(JNILibraryInitializer.java:132)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.addLibrary(NativeLibrarySupport.java:204)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary0(NativeLibrarySupport.java:160)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryAbsolute(NativeLibrarySupport.java:97)
at java.base@17.0.9/java.lang.ClassLoader.loadLibrary(ClassLoader.java:57)
at java.base@17.0.9/java.lang.Runtime.load0(Runtime.java:755)
at java.base@17.0.9/java.lang.System.load(System.java:1953)
at com.amazonaws.services.lambda.runtime.api.client.runtimeapi.JniHelper.unpackAndLoad(JniHelper.java:51)
at com.amazonaws.services.lambda.runtime.api.client.runtimeapi.JniHelper.load(JniHelper.java:38)
at com.amazonaws.services.lambda.runtime.api.client.runtimeapi.NativeClient.init(NativeClient.java:16)
at com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaRuntimeApiClientImpl.<init>(LambdaRuntimeApiClientImpl.java:41)
at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:203)
at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:190)
... 1 more
WtfJoke commented 3 weeks ago

@NikolayMetchev not sure if its still up to date, but 10 months ago I've made that sample project to test different cold start performance with jdk 21 https://github.com/WtfJoke/graalvm-java-21-lambda and it worked (but I think jni-config.json I used is identical with the one mentioned above.

The jni-config.json can be found here: https://github.com/WtfJoke/graalvm-java-21-lambda/blob/main/src/main/resources/META-INF/native-image/com.amazonaws/aws-lambda-java-runtime-interface-client/jni-config.json

smirnoal commented 3 weeks ago

@NikolayMetchev we added new JNI calls in recent RIC versions to clean up DNS cache (link). I guess this is why you are seeing the exception

NikolayMetchev commented 3 weeks ago

Thanks, It would be good to get this issue looked at. GraalVM seems to be a popular choice for lambda developers..I managed to actually use graalvm to generate a jni-config.json for me. It had a lot of stuff in there...