micronaut-projects / micronaut-maven-plugin

Maven plugin to execute Micronaut applications
https://micronaut-projects.github.io/micronaut-maven-plugin/latest/
Apache License 2.0
21 stars 21 forks source link

Lambda Failure Native Image deployments #373

Open sdelamo opened 2 years ago

sdelamo commented 2 years ago

Steps to reproduce:

You will need AWS CDK CLI installed and an AWS CLI. Run aws configure to point your AWS CLI to the appropriate account.

Clone this branch: esta rama https://github.com/micronaut-projects/micronaut-starter/pull/1204

For functions

Run

rm -rf starter-cli/temp;
./gradlew micronaut-cli:run --args="create-function-app -b maven -f \"aws-lambda,aws-cdk,graalvm\" temp";
cd starter-cli/temp;
./test-lambda.sh

Expected:

You should see success in the terminal. Instead, if you visit in the Lambda logs you will see the @ObjectMapper not being injected.

Please, not the same code works without native image.

If you run without the GraalVM feature. That it if you do:

./gradlew micronaut-cli:run --args="create-function-app -b maven -f \"aws-lambda,aws-cdk" temp";

instead of:

./gradlew micronaut-cli:run --args="create-function-app -b maven -f \"aws-lambda,aws-cdk" temp";

it works

For Applications

Run

rm -rf starter-cli/temp;
./gradlew micronaut-cli:run --args="create-app -b maven -f \"aws-lambda,aws-cdk,graalvm\" temp";
cd starter-cli/temp;
./test-lambda.sh

Expected:

You should see success in the terminal. Instead, it does not find the route tho the controller.

Without the graalvm feature it works.

alvarosanchez commented 2 years ago

For reference, the function logs are:

2022-05-18T12:37:23.449+02:00   START RequestId: c645395e-820c-4ca5-9429-b6f3a771b7be Version: $LATEST
2022-05-18T12:37:23.452+02:00   Invocation with requestId [c645395e-820c-4ca5-9429-b6f3a771b7be] failed: nulljava.lang.NullPointerException
2022-05-18T12:37:23.452+02:00   at temp.FunctionRequestHandler.execute(FunctionRequestHandler.java:19)
2022-05-18T12:37:23.452+02:00   at temp.FunctionRequestHandler.execute(FunctionRequestHandler.java:10)
2022-05-18T12:37:23.452+02:00   at io.micronaut.function.aws.MicronautRequestHandler.handleRequest(MicronautRequestHandler.java:128)
2022-05-18T12:37:23.452+02:00   at io.micronaut.function.aws.runtime.AbstractMicronautLambdaRuntime.startRuntimeApiEventLoop(AbstractMicronautLambdaRuntime.java:356)
2022-05-18T12:37:23.452+02:00   at io.micronaut.function.aws.runtime.AbstractMicronautLambdaRuntime.run(AbstractMicronautLambdaRuntime.java:137)
2022-05-18T12:37:23.452+02:00   at temp.FunctionLambdaRuntime.main(FunctionLambdaRuntime.java:13)
2022-05-18T12:37:23.454+02:00   END RequestId: c645395e-820c-4ca5-9429-b6f3a771b7be
2022-05-18T12:37:23.454+02:00   REPORT RequestId: c645395e-820c-4ca5-9429-b6f3a771b7be Duration: 3.40 ms Billed Duration: 4 ms Memory Size: 512 MB Max Memory Used: 82 MB XRAY TraceId: 1-6284cc63-2f3259c246369f9955aada51 SegmentId: 12cc0c542fa634e4 Sampled: true
sdelamo commented 2 years ago

The issue reproduced only for multi-module builds. I have created a repo with instructions to reproduce:

https://github.com/grails-core-issues-forks/micronaut-maven-plugin-issue-373

alvarosanchez commented 2 years ago

I used the provided sample, upgraded to 3.5.0:

diff --git a/350/pom.xml b/350/pom.xml
index f257686..b8e1a02 100644
--- a/350/pom.xml
+++ b/350/pom.xml
@@ -10,14 +10,14 @@
   <parent>
     <groupId>io.micronaut</groupId>
     <artifactId>micronaut-parent</artifactId>
-    <version>3.5.0-SNAPSHOT</version>
+    <version>3.5.0</version>
   </parent>

   <properties>
     <packaging>jar</packaging>
     <jdk.version>11</jdk.version>
     <release.version>11</release.version>
-    <micronaut.version>3.5.0-SNAPSHOT</micronaut.version>
+    <micronaut.version>3.5.0</micronaut.version>
     <micronaut.runtime>lambda</micronaut.runtime>
     <exec.mainClass>com.example.FunctionLambdaRuntime</exec.mainClass>
   </properties>
diff --git a/multimodule/app/pom.xml b/multimodule/app/pom.xml
index 7cc0ec1..b846fa2 100644
--- a/multimodule/app/pom.xml
+++ b/multimodule/app/pom.xml
@@ -16,7 +16,7 @@
     <packaging>jar</packaging>
     <jdk.version>11</jdk.version>
     <release.version>11</release.version>
-    <micronaut.version>3.5.0-SNAPSHOT</micronaut.version>
+    <micronaut.version>3.5.0</micronaut.version>
     <exec.mainClass>example.micronaut.FunctionLambdaRuntime</exec.mainClass>
     <micronaut.runtime>lambda</micronaut.runtime>
   </properties>
diff --git a/multimodule/pom.xml b/multimodule/pom.xml
index 8a7d57d..53e6c96 100644
--- a/multimodule/pom.xml
+++ b/multimodule/pom.xml
@@ -5,7 +5,7 @@
     <parent>
         <groupId>io.micronaut</groupId>
         <artifactId>micronaut-parent</artifactId>
-        <version>3.5.0-SNAPSHOT</version>
+        <version>3.5.0</version>
     </parent>

     <artifactId>temp-parent</artifactId>

Then created 2 functions, uploaded the corresponding function.zip to each of them, and tested with an empty JSON body.

Both fail the same way.

START RequestId: bc7da534-3263-48d3-b287-936eafb88ec2 Version: $LATEST
Invocation with requestId [bc7da534-3263-48d3-b287-936eafb88ec2] failed: nulljava.lang.NullPointerException
at com.example.FunctionRequestHandler.execute(FunctionRequestHandler.java:17)
at com.example.FunctionRequestHandler.execute(FunctionRequestHandler.java:9)
at io.micronaut.function.aws.MicronautRequestHandler.handleRequest(MicronautRequestHandler.java:128)
at io.micronaut.function.aws.runtime.AbstractMicronautLambdaRuntime.startRuntimeApiEventLoop(AbstractMicronautLambdaRuntime.java:356)
at io.micronaut.function.aws.runtime.AbstractMicronautLambdaRuntime.run(AbstractMicronautLambdaRuntime.java:137)
at com.example.FunctionLambdaRuntime.main(FunctionLambdaRuntime.java:12)
END RequestId: bc7da534-3263-48d3-b287-936eafb88ec2
REPORT RequestId: bc7da534-3263-48d3-b287-936eafb88ec2  Duration: 1.59 ms   Billed Duration: 2 ms   Memory Size: 128 MB Max Memory Used: 83 MB  

How could you make the single project version work?

sdelamo commented 1 year ago

@alvarosanchez could we give priority to this?

If we were able to generate the infrastructure as code for native deployment for maven, we could catch these errors earlier because I could native deployment for lambda in starter as we do for gradle.