Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
How do I return the data from S3 bucket in node?

I would like main() to return the data instead of just console logging it as shown below. How do I do it?

async function main() {
  // Load the AWS SDK for Node.js
  var AWS = require("aws-sdk");
  // Set the region
  AWS.config.update({ region: "REGION" });

  // Create S3 service object
  s3 = new AWS.S3({ apiVersion: "2006-03-01" });

  // Call S3 to list the buckets
  s3.listBuckets(function (err, data) {
    if (err) {
      console.log("Error", err);
    } else {
      console.log(data);
    }
  });
}
main();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try awaiting the listBuckets function.

Change

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

to

return await s3.listBuckets();

If that doesn't work, you can always just construct a manual Promise and resolve it with the data.

async function main() {
  // Load the AWS SDK for Node.js
  var AWS = require("aws-sdk");
  // Set the region
  AWS.config.update({ region: "REGION" });

  // Create S3 service object
  s3 = new AWS.S3({ apiVersion: "2006-03-01" });

  return await new Promise((resolve, reject) => {
    // Call S3 to list the buckets
    s3.listBuckets(function (err, data) {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
}
main();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!