title: AWS Lambda NoClassDefFoundError
body: <p>I am having difficulty with a Java based Lambda function setup to receive messages from SNS.  My function looks like the below:</p>
  
  <pre><code>package com.mycompany;
  
  import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.LambdaLogger;
  import com.amazonaws.services.lambda.runtime.events.SNSEvent;
  
  public class LambdaHandler {  
      public void Handler(SNSEvent event, Context context) {
          //Process the event
      }
  }
  </code></pre>
  
  <p>It compiles just fine and I don't have any problems uploading the jar file to Lambda (via the web console).</p>
  
  <p>However, when I publish to it (via SNS through to the subscribed Lambda function) with JSON representing the SNSEvent model, the Lambda function throws the following exception:</p>
  
  <blockquote>
    <p>Error loading method handler on class com.mycompany.LambdaHandler:
    class java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError:
    com/amazonaws/services/lambda/runtime/events/SNSEvent at</p>
    
    <p>java.lang.Class.getDeclaredMethods0(Native Method) at
    java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at
    java.lang.Class.privateGetPublicMethods(Class.java:2902) at
    java.lang.Class.getMethods(Class.java:1615) Caused by:
    java.lang.ClassNotFoundException:
    com.amazonaws.services.lambda.runtime.events.SNSEvent at
    java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
    java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
    java.lang.ClassLoader.loadClass(ClassLoader.java:357)</p>
  </blockquote>
  
  <p>I use Maven + Netbeans and it's a Maven Java Application project.  I downloaded the function from the Lambda console and confirmed, the jar has a lib/ directory with all of the jar's for the imports, including aws-lambda-java-events-1.1.0.jar, which itself includes the /com/amazonaws/services/lambda/runtime/events/SNSEvent.class file.</p>
  
  <p>Why is the runtime unable to find the class when it's definitely in the jar file?  Is there anything else I need to do, set any environment variables, etc?</p>
  
  <p>Any help would be appreciated!</p>
  
  <p><strong>EDIT 1</strong>
  I tried downgrading to aws-lambda-java-events 1.0.0 and it's still reporting the same exception.  As requested, below is my POM file (with just project name changed).  I don't know how to tell Maven to put the libraries in a tree structure.  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.app&lt;/groupId&gt;
      &lt;artifactId&gt;Handler&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
              &lt;artifactId&gt;aws-java-sdk-lambda&lt;/artifactId&gt;
              &lt;version&gt;1.10.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
              &lt;artifactId&gt;aws-lambda-java-core&lt;/artifactId&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
              &lt;artifactId&gt;aws-lambda-java-events&lt;/artifactId&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>