Search code examples
javascriptamazon-web-servicesaws-sdkes6-promise

No data returned in a aws-sdk Promise


I'm calling DynamoDB's PutItem as my first es6 promises attempt on AWS Lambda with Node 4.3.

Here's the relevant code:

var req = d.putItem(params={
  'TableName': TABLE,
  ...
}).promise();
req.then(function(resp) {
  console.log("sresp", resp);
  // I want to do more with the returned data here
});

And here's what shows up in the console:

sresp {}

There are a few questions about Promises in the AWS SDK (javascript) that are from the "pre-promises" era; as of March 2016 there's native support.


Solution

  • DynamoDB putItem request doesn't return anything by default. You have to specify a value for one or more of the following parameters in order to get something back (they all default to NONE):

      ReturnConsumedCapacity: 'INDEXES | TOTAL | NONE',
      ReturnItemCollectionMetrics: 'SIZE | NONE',
      ReturnValues: 'NONE | ALL_OLD | UPDATED_OLD | ALL_NEW | UPDATED_NEW'