lambci / docker-lambda

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

Java does not work with DOCKER_LAMBDA_USE_STDIN #143

Closed deecewan closed 5 years ago

deecewan commented 5 years ago

Running the java example (examples/java) with DOCKER_LAMBDA_USE_STDIN set results in an error:

Failed to load awslambda shared library: Library=libawslambda.so Exception=java.lang.ExceptionInInitializerError message=null
java.lang.ExceptionInInitializerError
    at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:233)
    at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104)
Caused by: java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:862)
    at java.util.Scanner.next(Scanner.java:1371)
    at lambdainternal.LambdaRuntime.getEventBody(LambdaRuntime.java:87)
    at lambdainternal.LambdaRuntime.<clinit>(LambdaRuntime.java:69)
    ... 5 more

You can reproduce with:

echo '{"some": "event"}' | docker run --rm -e DOCKER_LAMBDA_USE_STDIN=1 -v "$PWD/build/docker":/var/task lambci/lambda:java8 org.lambci.lambda.ExampleHandler

after running gradle build

mhart commented 5 years ago

You're missing the -i flag to docker run