Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quarkus-amazon-lambda @Inject doesn't work in JVM mode #3354

Closed
drissamri opened this issue Jul 26, 2019 · 13 comments
Closed

quarkus-amazon-lambda @Inject doesn't work in JVM mode #3354

drissamri opened this issue Jul 26, 2019 · 13 comments
Assignees
Labels
kind/question Further information is requested

Comments

@drissamri
Copy link
Contributor

drissamri commented Jul 26, 2019

Describe the bug
@Inject of services is not working, throwing a nullpointer at runtime.

Expected behavior
Services are created and injected

Actual behavior
No injection is happening:

java.lang.NullPointerException: java.lang.NullPointerException
java.lang.NullPointerException
at com.drissamri.ProductLambda.validateHealth(ProductLambda.java:39)
at com.drissamri.ProductLambda.handleRequest(ProductLambda.java:27)
at com.drissamri.ProductLambda.handleRequest(ProductLambda.java:12)

To Reproduce
Steps to reproduce the behavior:

  1. git clone [email protected]:drissamri/quarkus-jvm-dev-bug.git
  2. Install Serverless Framework for deployment to AWS
  3. mvn clean package -DskipTests
  4. serverless deploy
  5. Invoke the outputted endpoint

Environment (please complete the following information):

  • Output of uname -a or ver:
➜  ~ uname -a
Darwin localhost 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
  • Output of java -version:
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (Zulu 8.40.0.25-CA-macosx) (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (Zulu 8.40.0.25-CA-macosx) (build 25.222-b10, mixed mode)
  • Quarkus version or git rev:
    0.19.1

Additional context
I'm unable to test this locally due to #3352
Annotating the Handler class with @singleton doesn't help. I'm pretty sure it worked in native mode.

@drissamri drissamri added the kind/bug Something isn't working label Jul 26, 2019
@drissamri
Copy link
Contributor Author

https://stackoverflow.com/questions/56620352/quarkus-aws-lambda-function-cdi-doesnt-work-in-handler-class mentions CDI only works in native mode but I'm unable to find any official reference to this?

@drissamri
Copy link
Contributor Author

@evanchooly any idea on this one?

@evanchooly evanchooly self-assigned this Aug 9, 2019
@evanchooly
Copy link
Member

i'll take a look today. it's on my list to revisit that module today.

@evanchooly
Copy link
Member

having the serverless framework in the mix muddies the waters a bit but I'll see what I can find out. I think they're circumventing what what the quarkus module is doing somehow.

@drissamri
Copy link
Contributor Author

drissamri commented Aug 9, 2019

Serverless Framework only uploads the deployment package and doesn't impact any code, the same can be done with SAM CLI or CloudFormation

My colleague did the test on AWS SAM Local with the same result (running the uber jar)

@drissamri
Copy link
Contributor Author

Were you able to revisit that part @evanchooly? Does this have anything to do with the LambdaRecorder in native vs JVM mode?

@evanchooly
Copy link
Member

In your case it's because the serverless framework is invoking at the wrong spot and the quarkus bits aren't actually bootstrapped. i have ideas on how to clean that up but they're (largely) part of a refactoring that's been blocked by other changes. I'm working on it now, though.

@drissamri
Copy link
Contributor Author

drissamri commented Sep 9, 2019

Which other tickets are related to the refactor so I can have a look?

Serverless Framework just invokes the handler you define just like you would in AWS SAM/AWS CLI/other frameworks, so I'm afraid this is not something related to Serverless Framework?

@rkraneis
Copy link

Is there anything new? We have similar problems using quarkus-amazon-lambda-resteasy extension (NPE in StreamLambdaHandler as initHandler is not called before handleRequest).

@miron4dev
Copy link

Check the handler definition, it should be io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest

@kjuhasz
Copy link

kjuhasz commented Nov 18, 2019

And it really works using #3354 (comment) this method 😮 Can you share how you got to the solution?

@evanchooly
Copy link
Member

The docs are being updated as we speak (release pending) but here you can see the handler definition: https://quarkus.io/guides/amazon-lambda#create-the-function

I was able to run your project using the correct handler and correcting for a bug in checking the path ( if there is no path, the healthcheck code gets an NPE ). The HealthCheckService is properly injected. Updating accordingly should get you past it.

@rsvoboda
Copy link
Member

@evanchooly can be this closed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants