create an example for "aws-lambda-java" as a reference
Describe the Feature
Please provide another repository similar to this that illustrates how to use lambda containers with JAVA..
Is your Feature Request related to a problem?
Yes. I have been trying to create a simple lambda in java but keep on getting "java.lang.ClassNotFoundException" but there is no "aws-lambda-java" repository to use as a reference or raise issues on. Other users have been having the same problem e.g. https://stackoverflow.com/questions/65087659/aws-lambda-function-throws-classnotfoundexception
Proposed Solution
Provide another repository similar to this that illustrates how to use lambda containers with JAVA..
Describe alternatives you've considered
I tried going through the dotnet example but could not fix the problem.
Additional Context
I am testing how to deploy lambda functions using docker in JAVA. All the examples seem to either be in javascript or dotnet.
Environment
environment should not matter
This is a :rocket: Feature Request
Should be moved to https://github.com/aws/aws-sdk-java repository.
Hi @Alappin, you didn't mention specifically how you're building or deploying the Lambda containers so I'll share a couple of links that might help:
- The Lambda Developer Guide has Java Sample Apps and a section about deploying Java Lambda functions with container images
- How to troubleshoot "ClassNotFoundException" errors with my Java Lambda function: link
Let us know if you need further assistance.
Hi @debora-ito
Thanks for the response. Yes, I had gone through all those links including the troubleshooting guide, and could still not find a solution. All the other languages seem to have a working hello world like example e.g. nodejs, python, dotnet, e.t.c but Java does not have one. Following the guides just leads to ending up with an image that does not work as it throws that "ClassNotFoundException" error.
I had the docker file like below based of the usage instructions here https://hub.docker.com/r/amazon/aws-lambda-java
` FROM public.ecr.aws/lambda/java:11
COPY ./build/libs/app-all.jar ${LAMBDA_TASK_ROOT}/app.jar
CMD [ "com.example.LambdaHandler::handleRequest" ] `
The above container throws the following exception when a call is made locally. i.e.
docker run -p 9000:8080 <image name>
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
START RequestId: 4938a805-7daa-4938-a950-90c463086d73 Version: $LATEST Class not found: com.example.LambdaHandler java.lang.ClassNotFoundException
java.lang.ClassNotFoundException: com.example.LambdaHandler
at java.net.URLClassLoader.findClass ....
Even logged into the running container to make sure the JAR file is copied correctly. Unzipped and checked the files in the JAR file and everything looked ok. Gone through all the troubleshooting guides, and could not find an actual working example for Java lambda container image. Other users are getting this as shown in this here https://stackoverflow.com/questions/65087659/aws-lambda-function-throws-classnotfoundexception.
There must be something simple we are all missing, it would be nice if someone from AWS or whoever knows how the JAVA setup works provides an actual working example/sample with the dockerfile.
With the recently updated instructions on https://hub.docker.com/r/amazon/aws-lambda-java, I managed to resolve the "ClassNotFoundException" error. So I can now successfully run the java container image locally.
However, I found a bug after deploying the image. It now fails when deployed with the following error:
Unrecognized field "version" (class com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent), not marked as ignorable (12 known properties: "requestContext", "body", "queryStringParameters", "path", "headers", "httpMethod", "multiValueQueryStringParameters", "resource", "pathParameters", "isBase64Encoded", "stageVariables", "multiValueHeaders"])
It seems the latest java lambda events is missing the "version" field hence the event cannot be serialized without throwing an exception.
@Alappin the aws-lambda-java-events library is maintained by the AWS Lambda team, please open an issue in their repository and they'll be able to help you out: https://github.com/aws/aws-lambda-java-libs
COMMENT VISIBILITY WARNING
Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.