title: AWS DynamoDB trigger using Lambda in JAVA
body: <p>I am trying to trigger an AWS lambda function written in Java, on dynamodb stream events. Amazon has a guide for the same, using NodeJS here
  <a href="http://docs.aws.amazon.com/lambda/latest/dg/wt-ddb-create-test-function.html" rel="noreferrer">http://docs.aws.amazon.com/lambda/latest/dg/wt-ddb-create-test-function.html</a></p>
  
  <p>The testing input for NodeJS (from the above link) looks like an SNS event, so I tried to use the corresponding SNSEvent class in Java as an input to my handler method.</p>
  
  <pre><code>import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.LambdaLogger;
  import com.amazonaws.services.lambda.runtime.events.SNSEvent;
  import com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord;
  import java.util.List;
  
  public class RecomFunction {
  
      public void handler(SNSEvent event, Context context) {
  
          LambdaLogger logger = context.getLogger();
  
          List&lt;SNSRecord&gt; records = event.getRecords();
  
          if (records != null) {
              for (SNSRecord record : records) {
                  if (record != null) {
                      logger.log("SNS record: " + record.getSNS().getMessage());
                  }
              }
          }
      }
  
  }
  </code></pre>
  
  <p>Unfortunately, record.getSNS() returns NULL resulting to a NullPointer exception</p>
  
  <p>There is a related question, however a specific answer was not given:
  <a href="https://stackoverflow.com/questions/31589461/setup-dynamodb-trigger-using-lambda#">Setup DynamoDB Trigger using Lambda</a></p>