Home > Back-end >  Java AWS Lambda "ErrorMessage: Class not found
Java AWS Lambda "ErrorMessage: Class not found

Time:12-15

I'm trying to write a simple java lambda function. However I keep receiving this error when I run the lambda test after uploading the jar file for the lambda function:

{
  "errorMessage": "Class not found: org.example.HelloWorld.handler",
  "errorType": "java.lang.ClassNotFoundException"
}

Here is the Java code for the lambda:

package org.example;

/**
* Hello world!
*
*/
public class HelloWorld
{
    public String handler() {
        return "Hello World";
    }
}

For some more context this is a maven project, and I'm creating the jar file by running mvn clean package from the root LambdaExample directory.

Here is my file/directory structure for the project including the hello-lambda.jar that gets uploaded to AWS lambda . enter image description here

Here is my lambda function handler: enter image description here

Here is the lambda function summary: enter image description here

And here is full error output from AWS Lambda Test: enter image description here

This seems like a pretty basic project and I followed a tutorial (this one) so it should work. Anyone know why I'm getting this error and how I can fix it?

CodePudding user response:

You had a typo while specifying the handler in the runtime settings. The correct way to specify the handler is:

packageName.className::method

In your case, instead of:

org.example.HelloWorld.handler

Change to:

org.example.HelloWorld::handler

  • Related