How do I promisify the AWS JavaScript SDK?

后端 未结 8 1085
面向向阳花
面向向阳花 2020-12-08 18:52

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

Instead of the default callback style:

dynamodb.getItem(params, function(err, data) {
  if (         


        
8条回答
  •  失恋的感觉
    2020-12-08 19:11

    This solution works best for me:

    // Create a promise object
    var putObjectPromise = s3.putObject({Bucket: 'bucket', Key: 'key'}).promise(); 
    
    // If successful, do this:
    putObjectPromise.then(function(data) {
     console.log('PutObject succeeded'); })
    
    // If the promise failed, catch the error:
    .catch(function(err) { 
    console.log(err); });
    

提交回复
热议问题