Describe the bug
What is happening on #3354 is still happening: after deploying the JVM project, I get NPE in CloudWatch because the injected stuff is null.
Expected behavior
I'd like to have the services injected properly, not null...
Actual behavior
I follow all the indications in the guide https://quarkus.io/guides/amazon-lambda and the @ Inject members are null.
To Reproduce
Steps to reproduce the behavior:
I changed the inputs because my existing lambda reacts to a CloudWatch event, didn't want to fiddle with working AWS settings.
public String test() {
return "done";
}
implements RequestHandler<Object, Object> @Override
public Object handleRequest(Object input, Context context) {
return service.test();
}
Environment (please complete the following information):
uname -a or ver: Windows 10java -version: 11mvnw --version or gradlew --version): Maven 3.6.3Additional context
I must also say that I don't really understand what their mentioned "correct way" is in #3354, as it's not detailed, so the problem might be in front of the keyboard.
PS: I can't use native mode because I'm on Windows 10...
Created also a test project with all defaults as generated by the archetype. Generate the runner jar (not native), upload it as lambda, test in AWS console with a sample json and watch it crash.
https://github.com/sorin-costea/quarkus-inject
cc @oztimpower
Will take a look. Give me a few days.
@sorin-costea The sample project is working for me in all scenarios, via the Unit Test, via SAM Local and AWS.
If however I omit to pass the payload, or the JSON does not have the "name" property, then yes a NPE would be thrown from the ProcessingService:11 as opposed to an Inject failure. Injection was working.
I'll try your manual code as mentioned in the initial report, however I would appreciate if you could share your stack track from SAM Local or from AWS. How did you run and test this?
FYI #3354 is unrelated and the code has changed significantly since then.
Ok, I've modified the code as described above with your ProcessingService::test() function, and that also works with SAM Local and AWS.
Please share any stack traces, because the provided project and the manual explanation do not show a reproducer.
org.sorincos.TestLambda::handleRequest{
"name": "jim",
"greeting": "hi"
}
{
"errorMessage": "java.lang.NullPointerException",
"errorType": "java.lang.NullPointerException",
"stackTrace": [
"org.sorincos.TestLambda.handleRequest(TestLambda.java:25)",
"java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)",
"java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)",
"java.base/java.lang.reflect.Method.invoke(Unknown Source)"
]
}
and log output (service is null):
START RequestId: e11881f7-9cc6-4d27-a371-f53394c45a10 Version: $LATEST
May 29, 2020 2:47:14 PM org.sorincos.TestLambda handleRequest
INFO: service is: null
May 29, 2020 2:47:14 PM org.sorincos.TestLambda handleRequest
WARNING: WARN
May 29, 2020 2:47:14 PM org.sorincos.TestLambda handleRequest
SEVERE: SEV
java.lang.NullPointerException: java.lang.NullPointerException
java.lang.NullPointerException
at org.sorincos.TestLambda.handleRequest(TestLambda.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
END RequestId: e11881f7-9cc6-4d27-a371-f53394c45a10
REPORT RequestId: e11881f7-9cc6-4d27-a371-f53394c45a10 Duration: 535.28 ms Billed Duration: 600 ms Memory Size: 512 MB Max Memory Used: 96 MB Init Duration: 379.95 ms
Still works fine for me.
Local:
sam local invoke --template target/sam.jvm.yaml --event payload.json
__ ____ __ _____ ___ __ ____ ______
--/ __ \/ / / / _ | / _ \/ //_/ / / / __/
-/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2020-05-30 04:01:23,178 DEBUG [org.jbo.logging] (main) Logging Provider: org.jboss.logging.JBossLogManagerProvider
2020-05-30 04:01:24,800 DEBUG [org.jbo.threads] (main) JBoss Threads version 3.1.1.Final
START RequestId: 655fbfd0-9bc5-1433-bc2e-9e3d7686872e Version: $LATEST
2020-05-30 04:01:25,092 FINE [org.sor.TestLambda] (main) FINE
2020-05-30 04:01:25,093 INFO [org.sor.TestLambda] (main) service is: org.sorincos.ProcessingService@24c4ddae
2020-05-30 04:01:25,094 WARNING [org.sor.TestLambda] (main) WARN
2020-05-30 04:01:25,094 SEVERE [org.sor.TestLambda] (main) SEV
END RequestId: 655fbfd0-9bc5-1433-bc2e-9e3d7686872e
REPORT RequestId: 655fbfd0-9bc5-1433-bc2e-9e3d7686872e Init Duration: 2913.67 ms Duration: 52.21 ms Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 87 MB
{"result":"hello Bill","requestId":"655fbfd0-9bc5-1433-bc2e-9e3d7686872e"}
On AWS:
sh target/manage.sh invoke
Invoking function
++ aws lambda invoke response.txt --function-name Qtest --payload file://payload.json --log-type Tail --query LogResult --output text
++ base64 -d
START RequestId: acc56a45-7c7a-4834-86a2-1e8c75745f7b Version: $LATEST
2020-05-30 04:04:15,922 FINE [org.sor.TestLambda] (main) FINE
2020-05-30 04:04:15,922 INFO [org.sor.TestLambda] (main) service is: org.sorincos.ProcessingService@1f81aa00
2020-05-30 04:04:15,923 WARNING [org.sor.TestLambda] (main) WARN
2020-05-30 04:04:15,923 SEVERE [org.sor.TestLambda] (main) SEV
END RequestId: acc56a45-7c7a-4834-86a2-1e8c75745f7b
REPORT RequestId: acc56a45-7c7a-4834-86a2-1e8c75745f7b Duration: 155.17 ms Billed Duration: 200 ms Memory Size: 256 MB Max Memory Used: 113 MB Init Duration: 1620.50 ms
I note you listed the handler explicitly, is there a reason for this? If you look at the templates I am invoking, the handler is fixed as Quarkus; your handler is determined at build time via the Named annotation, and corresponding property in the application.properties.
I suspect this is your issue. If you use the SAM Local, which can run on Windows, you will see the definition, and also the templated target/manage.sh.
This is documented in the Quarkus Amazon Lambda guide
You have listed handler as:
handler: org.sorincos.TestLambda::handleRequest
when it is fixed as in the Quarkus templates:
io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest
@geoand Please close, discovered the issue as mentioned above.
@oztimpower I think you also have the rights to close issues, no?
Unfortunately, no.
Oh, okay
@oztimpower it might be obvious to you but I see no reference in the documentation that I should enter that handler in AWS, even if I was overriding it. So instead of closing the issue blindly can you please tell me what I should enter in the lambda handler? io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest throws ClassNotFoundException, same with io.quarkus.amazon.lambda.runtime.QuarkusHandler::handleRequest and same with test.
@geoand it's still not working.
I'll let you and @oztimpower figure it out. If you both think it should be reopened, I'll gladly reopen it
Hi @sorin-costea, look in the target/sam.jvm.yaml and the target/manage.sh for guidance.
I'm happy to get on a video call and walk through with you.
Can I suggest that you download SAM for Windows, and try the command I have above?
Let's take this offline, you can reach me on [email protected]
Using the SAM Template you can deploy, via sam deploy if needs be.
The handler is defined below, and the code to upload is function.zip
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Serverless Quarkus - qtest-1.0-SNAPSHOT
Globals:
Api:
EndpointConfiguration: REGIONAL
BinaryMediaTypes:
- "*/*"
Resources:
Qtest:
Type: AWS::Serverless::Function
Properties:
Handler: io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest
Runtime: java11
CodeUri: function.zip
MemorySize: 256
Timeout: 15
Policies: AWSLambdaBasicExecutionRole
For posterity: I was mistakenly uploading the runner.jar instead of the correct function.zip. That was all the difference.