Aws-sdk S3: Best Way To List All Keys With ListObjectsV2
Answer : this is the best way to do that in my opinion: const AWS = require('aws-sdk'); const s3 = new AWS.S3(); const listAllKeys = (params, out = []) => new Promise((resolve, reject) => { s3.listObjectsV2(params).promise() .then(({Contents, IsTruncated, NextContinuationToken}) => { out.push(...Contents); !IsTruncated ? resolve(out) : resolve(listAllKeys(Object.assign(params, {ContinuationToken: NextContinuationToken}), out)); }) .catch(reject); }); listAllKeys({Bucket: 'bucket-name'}) .then(console.log) .catch(console.log); Here is the code to get the list of keys from a bucket. var params = { Bucket: 'bucket-name' }; var allKeys = []; listAllKeys(); function listAllKeys() { s3.listObjectsV2(params, function (err, data) { if (err) { console.log(err, err.stack); // an error occurred } else { var contents = data.Contents; contents.forEach(function (c...