Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda: class java.lang.ClassNotFoundException

I am getting this message and I have no idea how to resolve it. Searched online and tried to implement their suggestion, but no luck yet. enter image description here

I basically followed the instructions specified in this link - http://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/lambda-tutorial.html

But instead of uploading the project using the AWS Management Console embedded in Eclipse, I tried to create a zip of my project and upload it to the AWS web console.

Below is structure of my project - enter image description here

That is it!! There is nothing fancy that I am trying to do here. It is just a HelloWorld example in Lambda.

Now, this is how I am creating the zip file, which is pretty straight forward in Eclipse - enter image description here

Once the zip is created I uploaded it to AWS Web console under the code tab - enter image description here

The Configuration tab looks something like this - enter image description here

Now when I am clicking the Test button it is unable to find the example.Hello class.

How come it is becoming so difficult for the Lambda Function to find this class? Can anyone suggest what possibly is going wrong in this execution??

Also attached the log statement, in case it helps -

enter image description here

like image 518
Rito Avatar asked Mar 09 '17 10:03

Rito


Video Answer


2 Answers

The following worked for me.

  1. Go to your lambda function in AWS Console
  2. Click on Code tab.
  3. Edit Run time settings
  4. Replace example.Hello::handleRequest with full class path of your stream handler. For example com.abc.company.app.StreamLambdaHandler::handleRequest
  5. Save it.
like image 151
Sandeep Kumar Avatar answered Oct 24 '22 23:10

Sandeep Kumar


I had the same problem, what worked for me was if you're running this from eclipse with maven, ensure you have the following plugin in your pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <artifactSet>
            <excludes>
              <exclude>com.amazonaws:aws-lambda-java-events</exclude>
              <exclude>com.amazonaws:aws-lambda-java-core</exclude>
            </excludes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>

Then run the project with: mvn package shade:shade to generate the jar artifacts in your target directory. After that, eclipse should upload the correct jar to lambda.

like image 45
Pete Avatar answered Oct 25 '22 01:10

Pete