How do I promisify the AWS JavaScript SDK?

Martin Kretz picture Martin Kretz · Oct 20, 2014 · Viewed 27.9k times · Source

I want to use the aws-sdk in JavaScript using promises.

Instead of the default callback style:

dynamodb.getItem(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

I instead want to use a promise style:

dynamoDb.putItemAsync(params).then(function(data) {
  console.log(data);           // successful response
}).catch(function(error) {
  console.log(err, err.stack); // an error occurred
});

Answer

Majix picture Majix · Apr 1, 2016

The 2.3.0 release of the AWS JavaScript SDK added support for promises: http://aws.amazon.com/releasenotes/8589740860839559