title: Insert to DynamoDB if item doesn't exits
body: <p>I'm setting up an attendance check on a streaming video with aws-rekognition, when a person is identified then a lambda should write it to a DynamoDB. the <code>insertDynamo()</code>works fine alone(when I'm not calling it as function),but when I put it inside a function, it doesn't write to the DynamoDB table. Any idea on what am doing wrong?</p>
  
  <pre class="lang-java prettyprint-override"><code>var AWS = require('aws-sdk');
  var today = new Date();
  var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
  var hour = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  
  exports.handler = async (event, context) =&gt; {
      //console.log('Received event:', JSON.stringify(event, null, 2));
  
  
      event.Records.forEach((record) =&gt; {
  
              // Kinesis data is base64 encoded so decode here
              const load = new Buffer(record.kinesis.data, 'base64').toString('ascii');
              const payload = JSON.parse(load);
             if(payload.FaceSearchResponse != null)
             {
                 payload.FaceSearchResponse.forEach((face) =&gt;  {
  
                     if(face.MatchedFaces != null &amp;&amp; 
                           Object.keys(face.MatchedFaces).length &gt; 0)
                     {
                         var id = JSON.stringify(face.MatchedFaces[0].Face.ExternalImageId, null, 4);
                         //this is hard code it ---needs to split string from kinesis(id)
                         insertDynamo(date,hour,'0001');
                     }
                     else
                     {
                         //do nothing
                     }
                 });
             }
          });
      return `Successfully processed ${event.Records.length} records.`;
  };
  
  var insertDynamo = function(date,hour,id){
      exports.handler = async (event,context) =&gt; {
      const documentClient = new AWS.DynamoDB.DocumentClient();
      let responseBody = "";
      let statusCode = 0;
  
      const params = {
          TableName: "users",
          Item:{
              badgeNumber: id,
              assistance:{
                  date:date,
                  hour:hour
              }
          },
          ConditionExpression: 'attribute_not_exists(badgenumber)'    
      };
  
      try {
          const data = await documentClient.put(params).promise();
          responseBody = JSON.stringify(data);
          statusCode = 201;
      } catch (err) {
          responseBody = `Unable to put product: ${err}`;
          statusCode = 403;
      }    
  
      const response = {
          statusCode: statusCode,
          headers: {
              "Content-Type": "application/json"
          },
          body:responseBody
      }
      return response
  }
  };
  </code></pre>