title: AWS Lambda ClassNotFoundException
body: <p>I am having trouble when lambda function is called on dynamoDB update.
  i have checked 
  <a href="https://stackoverflow.com/questions/46943897/aws-lambda-classnotfoundexception">AWS Lambda: ClassNotFoundException</a>
  and 
  <a href="https://stackoverflow.com/questions/32782980/aws-lambda-noclassdeffounderror">AWS Lambda NoClassDefFoundError</a>
  but no success.</p>
  
  <p>i am writing this lambda function to call when there is any update in dynamo . i followed this tutorial.
  <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-dynamodb-create-package.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/lambda/latest/dg/with-dynamodb-create-package.html</a></p>
  
  <p>All the thing have been done successfully but the problem is when i update dynamodb and check the logs for AWS Cloud watch there is an exception.</p>
  
  <pre><code>Error loading method handleRequest on class com.amazonaws.lambda.demo.LambdaFunctionHandler: java.lang.NoClassDefFoundError
  java.lang.NoClassDefFoundError: com/amazonaws/services/lambda/runtime/events/DynamodbEvent
  at 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.DynamodbEvent
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 4 more
  </code></pre>
  
  <p>my java code is.</p>
  
  <pre><code>package com.amazonaws.lambda.demo;
  
  import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.RequestHandler;
  import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
  import com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord;
  
  
  public class LambdaFunctionHandler implements RequestHandler&lt;DynamodbEvent, String&gt; {
  
      @Override
      public String handleRequest(DynamodbEvent ddbEvent, Context context) {
          // TODO Auto-generated method stub
          for (DynamodbStreamRecord record : ddbEvent.getRecords()){
                 System.out.println(record.getEventID());
                 System.out.println(record.getEventName());
                 System.out.println(record.getDynamodb().toString());
  
              }
              return "Successfully processed " + ddbEvent.getRecords().size() + " records.";
      }
  
  }
  </code></pre>
  
  <p>my pom.xml is </p>
  
  <pre><code>&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.amazonaws.lambda&lt;/groupId&gt;
    &lt;artifactId&gt;demo&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
  
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.6.0&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.8&lt;/source&gt;
            &lt;target&gt;1.8&lt;/target&gt;
            &lt;encoding&gt;UTF-8&lt;/encoding&gt;
            &lt;forceJavacCompilerUse&gt;true&lt;/forceJavacCompilerUse&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.0.0&lt;/version&gt;
          &lt;configuration&gt;
        &lt;createDependencyReducedPom&gt;false&lt;/createDependencyReducedPom&gt;
      &lt;/configuration&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;shade&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  
    &lt;dependencyManagement&gt;
      &lt;dependencies&gt;
        &lt;dependency&gt;
          &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
          &lt;artifactId&gt;aws-java-sdk-bom&lt;/artifactId&gt;
          &lt;version&gt;1.11.321&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
          &lt;scope&gt;import&lt;/scope&gt;
        &lt;/dependency&gt;
      &lt;/dependencies&gt;
    &lt;/dependencyManagement&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;4.12&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&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.3.0&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.1.0&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>i am naming my handler as <code>com.amazonaws.lambda.demo.LambdaFunctionHandler::handleRequest</code></p>
  
  <p>i have checked all the things are fine but still it is giving me error on <code>com.amazonaws.services.lambda.runtime.events.DynamodbEvent</code> this class is in aws sdk.</p>
  
  <p>dependency tree.
  <a href="https://i.stack.imgur.com/dgKmr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dgKmr.png" alt="enter image description here"></a></p>