viveksinghggits
viveksinghggits

Reputation: 680

AWS lambda is not able to find the class that is given in handler

I wrote a simple java program that will take a Person object in JSON format and return a string message. The dependencies are being maintained by Maven and below are all the dependencies that have been included in the pom.xml

aws-lambda-java-core
maven-shade-plugin

I have included maven-shade-plugin as plugin also apart from the dependency and ran the maven build with the goal package shade:shade. After the successful build I deployed the app-1.0-SNAPSHOT-shaded.jar file into the lambda function that I created, when I test this function I am getting below response and was not able to resolve the issue.

{ "errorMessage": "Class not found: com.abc.nimbus.Handler", "errorType": "java.lang.ClassNotFoundException" }

below is the class that is implementing the RequestHandler interface

package com.abc.nimbus;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Handler implements RequestHandler<Person, String>{

    public String handleRequest(Person input, Context context) {
        return "Got the message";
    }
}

and the value of the handler of the lambda function is com.abc.nimbus.Handler::handleRequest

Upvotes: 5

Views: 3587

Answers (2)

Ashwini Kondalakadu
Ashwini Kondalakadu

Reputation: 79

verify if the application has built properly. You can also use 'install shade:shade' command to build the project. Make sure that the configuration in aws console points to the exact class and method of the Lambda code.

Upvotes: 0

monkey intern
monkey intern

Reputation: 726

Some things you can check, based on my not so extense experience:

  1. Check the size of the package uploaded. I have had that error when I was not properly building the maven project, and when I realized I checked the file in S3 it was less than 1MB, when (in my case) is usually around 70MB. So it was not properly built.

  2. Personally I am using eclipse:eclipse as goal, maybe you can try that, see if it works.

  3. Check that lambda is pointing to the right version of your packaged code and if any VPC should be configured.

I hope it helps.

Upvotes: 2

Related Questions