How do you list all objects in an S3 bucket using Node.js?

Responsive Ad Header

Question

Grade: Education Subject: Support
How do you list all objects in an S3 bucket using Node.js?
Asked by:
58 Viewed 58 Answers

Answer (58)

Best Answer
(404)
You can use the `listObjectsV2` method of the S3 client. This method returns a list of objects within the specified bucket. ```javascript const AWS = require('aws-sdk'); const s3 = new AWS.S3(); const params = { Bucket: 'your-bucket-name' }; const data = await s3.listObjectsV2(params).promise(); console.log(data.Contents); ``` The `Contents` property will contain an array of object information.