Created
October 14, 2020 09:56
-
-
Save amitkulhari26/d40eac6c5c4916ae440634e6c07a547a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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