title: AWS node.js lambda request dynamodb but no response (no err, no return data)
body: <p>I am playing the aws mobilehub with react-native and I was hoping that it can speed up the backend hosting for me. </p>
  
  <p>However, I cannot get its backend API working. After a long run with their docs, I pin down the problem between its lambda function and dynamodb service. </p>
  
  <p>Any thoughts are greatly appreciated!</p>
  
  <h3>Problem#1</h3>
  
  <p>As the titled says: my aws lambda functions can request its dynamodb but has no response. 
  What went wrong here? 
  Or how can I get debug info from AWS dynamodb? (I gg and enabled Cloudtrial but it doesn't seem to have operation logs of the dynamodb too.)</p>
  
  <h3>Lambda side</h3>
  
  <p>Here I have the simplest node.js 6.10 codes:</p>
  
  <pre><code>const AWS = require('aws-sdk');
  AWS.config.update({region: 'us-east-2'});
  const dynamodb = new AWS.DynamoDB.DocumentClient();
  
  exports.handler = function(event, context, callback) {
      var responseCode = 200;
      var requestBody, httpMethod, res;
      console.log("request: " + JSON.stringify(event));
  
      // Request Body
      requestBody = event.body;
  
      /*testing dynamodb with put*/
  
      console.log("PUT begins");
      let putItemParams2 = {
          TableName: "xxxx-mobilehub-xxxx-Test",//tableName
          Item: {businessId:'putItemParams2r3',test:'yooo', hmm:'hhhh'}
      };
      console.log("putItemParams2: ",putItemParams2);
      dynamodb.put(putItemParams2, (err, data) =&gt; {
          console.log("putItemParams2");
          if (err) console.log("dynamodb err: ",err, err.stack); // an error occurred
          else     console.log("dynamodb data: ",data);           // successful response
      });
      console.log("PUT end");
  
      var response = {
          statusCode: responseCode
          //....
      };
  
      ...
      //comment out context.succeed here to avoid program termination before intended. 
      //console.log("response: " + JSON.stringify(response))
      //context.succeed(response);
  };
  </code></pre>
  
  <h3>Logs</h3>
  
  <p>When the previouse codes are triggered, from AWS CloudWatch I can see logs:</p>
  
  <pre><code>START RequestId: 3d7c5f7f-1b98-11e8-ad00-93a6d10c8f4e Version: $LATEST
  [timestamp] PUT begins
  [timestamp] putItemParams2: { TableName: 'xxx-mobilehub-xxxx-Test',
  Item: { businessId: 'putItemParams2r3', test: 'yooo', hmm: 'hhhh'}}
  [timestamp] put end
  END RequestId: 3d7c5f7f-1b98-11e8-ad00-93a6d10c8f4e
  </code></pre>
  
  <p>So no err, no data, no response. I checked my dynamodb and there is nothing insert. </p>
  
  <h3>Extra info</h3>
  
  <p>condition#1: this dynamodb table has public access since I want to rule out the auth problem.</p>
  
  <p>condition#2: I ensure that my lambda function has access to these tables. e.g. arn:aws:dynamodb:<em>:xxxx:table/xxxx-mobilehub-xxxx-</em>  allow everything</p>
  
  <p>condition#3: I build myself a simple node.js to execute the (aws-sdk)and this server works perfectly fine with the same code.. 
  I am able to "get" &amp;"put" items int &amp; out from my dynamodb table.</p>
  
  <h2>Problem#2</h2>
  
  <p>my react-native code use 'aws-amplify-react-native'. Which the API.put is fine and the lambda function is at least receiving the api call (from problem#1).</p>
  
  <p>However, API.get returns me 403 error, and the lambda function doesn't even has log for this operation.. </p>
  
  <pre><code>async function getBusiness(){
      const path = "/Test";
      const api = "TestCRUD";
      let queryGetBusiness = {body: {userId: "hmmm"}};
  
      try {
          let apiResponse = await API.get(api, path, queryGetBusiness)//.then((data)=&gt;{console.log(data)});
          let apiResponseJson = await JSON.stringify(apiResponse);
          console.log("response from saving Business: " + apiResponseJson);
      }
      catch (e) {console.log(e);}
  } 
  </code></pre>
  
  <p>P.S.(AWS could do much better with this mobilehub.. their documentation is lacking details and awsmobile cloud-api invoke has some problems I guess.)</p>