Created
August 18, 2019 06:45
-
-
Save tksst/a357e9b1a95e652ab20985df52da76b7 to your computer and use it in GitHub Desktop.
This file contains 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
import S3 from "aws-sdk/clients/s3"; | |
const s3 = new S3(); | |
export async function* s3ListAllObjects(bucketName: string, limit: number = Number.MAX_VALUE) { | |
let p = s3.listObjectsV2({ Bucket: bucketName }).promise(); | |
for (let i = 0; i < limit; ++i) { | |
const result = await p; | |
if (!result.IsTruncated || result.NextContinuationToken === undefined) { | |
yield result.Contents; | |
break; | |
} | |
p = s3.listObjectsV2({ Bucket: bucketName, ContinuationToken: result.NextContinuationToken }).promise(); | |
yield result.Contents; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment