How to read a file from AWS S3 bucket using Node.js fs module?

Sometimes, we want to read a file from AWS S3 bucket using Node.js fs module.

In this article, we’ll look at how to read a file from AWS S3 bucket using Node.js fs module.

How to read a file from AWS S3 bucket using Node.js fs module?

To read a file from AWS S3 bucket using Node.js fs module, we can use the s3.getObject method.

For instance, we write

s3.getObject({
  Bucket,
  Key: keyName
}, (err, data) => {
  if (err) {
    return
  }
  console.log(data);
});

to call getObject with params which has the bucket and key.

Then we get the read file from the data parameter in the callback.

Conclusion

To read a file from AWS S3 bucket using Node.js fs module, we can use the s3.getObject method.