I started a spring boot brand new project using initializr. I use maven3, Graalvm 23, Spring boot 3.4.1. Every time I start it in AWS lambda environment in Amazon Linux 2023, I get the following exception:
Caused by: java.lang.NullPointerException
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getFieldID(JNIFunctions.java:1858)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetFieldID(JNIFunctions.java:461)
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:70)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.JNILibraryInitializer.initialize(JNILibraryInitializer.java:131)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.addLibrary(NativeLibrarySupport.java:128)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.addLibrary(NativeLibrarySupport.java:84)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibraries.loadLibrary0(NativeLibraries.java:147)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibraries.loadLibraryAbsolute(NativeLibraries.java:102)
at java.base@23.0.1/java.lang.ClassLoader.loadLibrary(ClassLoader.java:116)
at java.base@23.0.1/java.lang.Runtime.load0(Runtime.java:852)
at java.base@23.0.1/java.lang.System.load(System.java:2028)
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)
... 2 more
EXTENSION Name: cloudwatch_lambda_agent State: Ready Events: [INVOKE, SHUTDOWN]
INIT_REPORT Init Duration: 778.63 ms Phase: invoke Status: error Error Type: Runtime.ExitError
My config:
<properties>
<core.version>1.0-SNAPSHOT</core.version>
</properties>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-springboot3</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>9.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<id>enhance</id>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
<configuration>
<agent>
<enabled>true</enabled>
</agent>
<mainClass>com.amazonaws.services.lambda.runtime.api.client.AWSLambda</mainClass>
<imageName>kount-worker</imageName>
<buildArgs>
<buildArg>-H:DynamicProxyConfigurationFiles=src/main/resources/META-INF/native-image/com.mycompany/kount/proxies.json</buildArg>
<buildArg>--emit build-report</buildArg>
<buildArg>-Os</buildArg>
<buildArg>-H:-ReduceImplicitExceptionStackTraceInformation</buildArg>
<buildArg>-H:ResourceConfigurationFiles=src/main/resources/META-INF/native-image/com.mycompany/kount/resource-config.json</buildArg>
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
<!-- <buildArg>-H:JNIConfigurationFiles=src/main/resources/jni-config.json</buildArg>-->
<buildArg>--verbose</buildArg>
<buildArg>--enable-url-protocols=http</buildArg>
<!-- <buildArg>-march=native</buildArg>-->
<buildArg>-H:ReflectionConfigurationFiles=src/main/resources/META-INF/native-image/com.mycompany/kount/reflect-config.json</buildArg>
<buildArg>
--initialize-at-build-time=org.springframework.boot.loader.nio.file.NestedFileSystemProvider
</buildArg>
<buildArg>--enable-all-security-services</buildArg>
<buildArg>--enable-http</buildArg>
<buildArg>--enable-https</buildArg>
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<finalName>kount-worker</finalName>
</configuration>
<version>3.2.0</version>
</plugin>
</plugins>
</build>
</project>
So what I did: 1. Started a brand new project 2. Compiled it into jar 3. Ran graalvm native agent, collected all data to META-INF/... folder 4. Compiled native image again 5. Uploaded it into AWS Lambda Getting the same load JNI NPE over and over again. No information which class not loaded, nothing
I think it's a bug in using AL2023, correct me if I'm wrong, thanks
Comment From: snicoll
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.
Comment From: astsiatsko
Thanks for the comment, but I really think it's a bug, the same I can see here https://github.com/aws/aws-lambda-java-libs/issues/272
Comment From: snicoll
It could very well be but taking more time to narrow down the actual problem was in order. Spring Boot doesn't provide the AWS integration either.