title: Errors when using a Lambda function to delete a record from dynamoDB, yet record is still deleted
body: <p>I am attempting to delete a record from DynamoDB using Lambda and API gateway. Currently the Id of the record is passed as a query parameter, which is passed to my deleteRecord lambda function, and used in the delete function of the documentClient.</p>
  
  <p>Currently, I receive errors when trying to delete a record, yet the record is deleted anyway, and I can't figure out why.</p>
  
  <p>When testing on the API gateway, I receive "Internal server error" as a response, yet inspection of the table shows that the item is deleted, and the logs show me the record that has been deleted (as per supplying <strong>ReturnValues: "ALL_OLD"</strong> in the <em>params</em> passed to documentClient).</p>
  
  <p>When testing on Lambda directly (manually inserting the ID into my <em>dt.delete</em> function), I get the following:</p>
  
  <pre><code>Response:
  {
    "errorMessage": "RequestId: xxxxxxxxxxxxxxxxxxxx Process exited before completing request"
  }
  
  Request ID:
  "xxxxxxxxxxxxxxxxxxxx"
  
  Function Logs:
  START RequestId: xxxxxxxxxxxxxxxxxxxx Version: $LATEST
  2019-04-04T10:21:55.637Z    xxxxxxxxxxxxxxxxxxxx    Promise { &lt;pending&gt; }
  2019-04-04T10:21:55.938Z    xxxxxxxxxxxxxxxxxxxx    TypeError: undefined is not a function
      at Response.&lt;anonymous&gt; (/var/task/deleteTrip.js:28:28)
      at Request.&lt;anonymous&gt; (/var/runtime/node_modules/aws-sdk/lib/request.js:364:18)
      at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
      at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
      at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
      at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
      at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
      at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
      at Request.&lt;anonymous&gt; (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
      at Request.&lt;anonymous&gt; (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)
  END RequestId: xxxxxxxxxxxxxxxxxxxx
  REPORT RequestId: xxxxxxxxxxxxxxxxxxxx  Duration: 941.48 ms Billed Duration: 1000 ms    Memory Size: 128 MB Max Memory Used: 67 MB  
  RequestId: xxxxxxxxxxxxxxxxxxxx Process exited before completing request
  </code></pre>
  
  <p>Despite the error, the record is deleted from the table in this instance as well.</p>
  
  <p>I have followed the <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#delete-property" rel="nofollow noreferrer">DocumentClient documentation</a> for deleting a record, however it does not explain how to pass back a response (instead just logs the data from the call back), so I am not sure if this is my problem.</p>
  
  <p><strong>Lambda Functions</strong><br>
  Index.js:</p>
  
  <pre><code>const deleteTrip = require('./deleteTrip.js');
  const dt = new deleteTrip();
  
  exports.handler = async (event) =&gt; {
      return dt.delete(event.queryStringParameters['Id']);
  };
  </code></pre>
  
  <p>deleteTrip.js:</p>
  
  <pre><code>const AWS = require('aws-sdk');
  
  let documentClient = new AWS.DynamoDB.DocumentClient({
      'region': 'eu-west-1'
  });
  
  module.exports = class deleteTrip {
      delete(Id) {
          return new Promise((resolve, reject) =&gt; {
              if (typeof Id !== 'string') throw `Expected: "String", received: ${typeof Id}`;
              let params = {
                  TableName: "xyzDataTable",
                  Key: {
                      tripId: Id
                  },
                  ReturnValues: "ALL_OLD",
                  Exists: true
              };
              documentClient.delete(params, function(err, data) {
                  if (err) {
                      console.log("Error deleting record from dynamoDB:", err);
                      console.log(params);
                      return reject(err);
                  } else {
                      return resolve(...data.Attributes);
                  }
              })
          });
  
      }
  }
  </code></pre>
  
  <p>I expect the details of the deleted item to be returned if the request was successful, and an error to be thrown if not.</p>