Skip to content

Instantly share code, notes, and snippets.

@amitkulhari26
Created October 14, 2020 09:56
Show Gist options
  • Select an option

  • Save amitkulhari26/d40eac6c5c4916ae440634e6c07a547a to your computer and use it in GitHub Desktop.

Select an option

Save amitkulhari26/d40eac6c5c4916ae440634e6c07a547a to your computer and use it in GitHub Desktop.
// https://menno.io/posts/listing-s3-objects-with-nodejs/
async function allBucketKeys(s3, bucket) {
const params = {
Bucket: bucket,
};
var keys = [];
for (;;) {
var data = await s3.listObjects(params).promise();
data.Contents.forEach((elem) => {
keys = keys.concat(elem.Key);
});
if (!data.IsTruncated) {
break;
}
params.Marker = data.NextMarker;
}
return keys;
}
// Remember to catch exceptions somewhere...
const s3 = connectToS3Somehow();
var keys = await allBucketKeys(s3, "my_bucket");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment