0
votes

I am just trying basic list all my buckets, but its not firing, any idea what i might be doing wrong?

'use strict';
var AWS = require('aws-sdk');
var s3 = new AWS.S3();

module.exports.hello = async (event, context) => {
  // console.log("hi yall");
  // return "hello";
  var params = {};
 s3.listBuckets(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
 });

};

return value is null and the following is my log output

START RequestId: 827acca9-3e91-405d-a031-7fac249284a0 Version: $LATEST END RequestId: 827acca9-3e91-405d-a031-7fac249284a0 REPORT RequestId: 827acca9-3e91-405d-a031-7fac249284a0 Duration: 45.66 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB

3

3 Answers

2
votes

if you use async you should promisify the AWS function and await it like this:

   'use strict';
   var AWS = require('aws-sdk');
   var s3 = new AWS.S3();

   module.exports.handler = async (event, context) => {

     var params = {};
     let data = await s3.listBuckets(params).promise();
     console.log(data); 
     }
0
votes

Try this:

 s3.listBuckets(function(err, data) {
   if (err) console.log(err, err.stack); 
   else     console.log(data);           
 });

Have you set properly AWS settings?

0
votes

I figured it out. One should remove async and it works, not sure why but it does work now. If someone can drop the explanation here that would be great!