lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

Java8 fails without providing a clue to the issue #290

Closed malbanesi-ascii closed 4 years ago

malbanesi-ascii commented 4 years ago

I've lost an evening on this mystifying null printed in red color, right after START RequestId..., using the lambci/lambda:java8 image:

Lambda API listening on port 9001...
2020/06/30 23:03:17 In /invocation/next
2020/06/30 23:03:17 Waiting for next event...
START RequestId: c343fe41-5ccc-1048-6764-3b85a9a6f45b Version: $LATEST
null
2020/06/30 23:03:22 Could not parse error body as JSON
2020/06/30 23:03:22 []
2020/06/30 23:03:22 Setting Reply in handleErrorRequest
2020/06/30 23:03:22 &{ InvalidErrorShape [] <nil>}
Exception in thread "main" java.lang.Error: java.lang.RuntimeException: java.lang.RuntimeException: Unexpected status code from invocation/response: 299
    at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:65)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:119)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Unexpected status code from invocation/response: 299
    at lambdainternal.LambdaRuntime.reportDone(LambdaRuntime.java:227)
    at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:366)
    at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:63)
    ... 3 more
Caused by: java.lang.RuntimeException: Unexpected status code from invocation/response: 299
    at lambdainternal.LambdaRuntime.reportDone(LambdaRuntime.java:224)
    ... 5 more

But the issue was immediately identified when running the Java 11 base image:

Status: Downloaded newer image for lambci/lambda:java11
2020/06/30 23:05:36 In /invocation/next
2020/06/30 23:05:36 Waiting for next event...
START RequestId: b6f3d15d-2f75-1b3e-3b62-4047ad7bb6f2 Version: $LATEST
2020/06/30 23:05:36 Setting Reply in handleErrorRequest
2020/06/30 23:05:36 &{ Class does not implement an appropriate handler interface: com.company.product.Handler [] <nil>}
Class does not implement an appropriate handler interface: com.company.product.Handler
2020/06/30 23:05:36 In /invocation/next
2020/06/30 23:05:36 Reply is not nil
2020/06/30 23:05:36 EndInvoke()
END RequestId: b6f3d15d-2f75-1b3e-3b62-4047ad7bb6f2

The cause of the problem was this lambda did not implement the RequestHandler interface - someting AWS Lambda allows, but the java8 image rejects with the unhelpful error above.

Could the validations added to :java11 be backported to :java8 to prevent others from tripping over this?

Thank you

mhart commented 4 years ago

These seem like different errors to me – the first is a parsing error.

  1. How are you invoking the Lambda in the first example?
  2. Have you verified that your Lambda works on the java11 runtime in production?
mhart commented 4 years ago

It's your "something AWS Lambda allows" statement that I'm confused by – can you explain what you mean by that?

malbanesi-ascii commented 4 years ago

"something AWS Lambda allows" I meant that the code I'm working on, did NOT implement the RequestHandler interface - and it was running on AWS Lambda with the java8 runtime in production for months.

Screen Shot 2020-07-01 at 11 29 56 AM

The lambci/lambda:java11 base image reported the class didn't implement the necessary interface immediately. But lambci/lambda:java8 failed without any helpful message as to the cause of the problem.

mhart commented 4 years ago

I think if it runs on the AWS Lambda java8 runtime, then it should run on docker-lambda too. If it doesn't, then there's something up.

Does your code run on the Lambda java11 runtime?

mhart commented 4 years ago

Btw, are you sure you're using the same handler with docker-lambda as you are on AWS Lambda?

If you're using a POJO, then you have to specify the method name as part of your handler. ie, com.company.product.Handler::handleRequest.

If you don't specify the method name, then Lambda will assume that you're implementing RequestHandler.

I think this should be the same on production Lambda?

mhart commented 4 years ago

The error output on the java8 runtime should be cleaner now. I'm going to close this, but feel free to reopen if you keep running into trouble