Created
May 31, 2017 15:45
-
-
Save dakatsuka/8c73c8232b95e70c7baf1a5fee74b2bc to your computer and use it in GitHub Desktop.
List s3 keys recursively
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 scala.collection.JavaConverters._ | |
val request = new ListObjectsV2Request() | |
request.setBucketName(bucket) | |
request.setPrefix(prefix) | |
@tailrec | |
def fetch(req: ListObjectsV2Request, xs: Iterable[String]): Iterable[String] = { | |
val result = s3Client.listObjectsV2(req) | |
val keys = xs ++ result.getObjectSummaries.asScala.map(_.getKey) | |
if (result.isTruncated) { | |
req.setContinuationToken(result.getNextContinuationToken) | |
fetch(req, keys) | |
} else keys | |
} | |
Source(fetch(request, Iterable.empty[String]).toList) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment