title: AWS Lambda function returns error from API Gateway, but not when invoked directly
body: <p>I have a simple Lambda function which writes items to a DynamoDB table. 
  username is partition key, createDateTime is sort key. </p>
  
  <p>Invoking this function from Lambda itself successfully inserts items into the table. However when called through API Gateway, I'm receiving the following error </p>
  
  <pre><code>{
    "errorMessage": "Error putting order into dynamodb: MultipleValidationErrors: There were 14 validation errors:\n* InvalidParameterType: Expected params.Item['createDateTime'] to be a structure\n* UnexpectedParameter: Unexpected key '0' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '1' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '2' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '3' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '4' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '5' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '6' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '7' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '8' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '9' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '10' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '11' found in params.Item['createDateTime']\n* UnexpectedParameter: Unexpected key '12' found in params.Item['createDateTime']"
  }
  </code></pre>
  
  <p>I fail to understand why my code works when invoked locally, but not when invoked through API Gateway? Code below:</p>
  
  <pre><code>var AWS = require("aws-sdk");
  var DOC = require("dynamodb-doc");
  
  AWS.config.update({region: "eu-west-1"});
  var dynamodb = new DOC.DynamoDB();
  
  exports.handler = function(event, context) {
      console.log('Received event:', JSON.stringify(event, null, 2));
  
      var tableName = "MarketOrder";
  
      if (event.http_method == 'POST') {
          var datetime = new Date().getTime().toString();
  
          dynamodb.putItem({
              "TableName": tableName,
              "Item" : { 
                  "username"   : event.username,
                  "createDateTime" : datetime,
                  "orderType": event.orderType,
                  "numberOfShares": event.numberOfShares,
                  "price": event.price,
                  "validToDate": event.validToDate
              }
          }, function(err, data) {
              if (err) {
                  console.log("dynamodb error: " + err);
                  context.done('Error putting order into dynamodb: ' +err);
              }
              else {
                  console.log('great success: '+JSON.stringify(data, null, '  '));
                  context.succeed('Sucessfully saved market order');
              }
          });
      } 
      ....
      } else {
          context.fail('Invalid operation specified:' + event.http_method);
      }
  };
  </code></pre>