Skip to content

Instantly share code, notes, and snippets.

@justhackit
Last active July 12, 2021 21:00
Show Gist options
  • Save justhackit/e2e9d2c3560e6efeb4caa3f974bb2cb8 to your computer and use it in GitHub Desktop.
Save justhackit/e2e9d2c3560e6efeb4caa3f974bb2cb8 to your computer and use it in GitHub Desktop.
def getFileSizes(bucketName: String, prefix: String): scala.collection.immutable.Map[String, Long] = {
val s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build()
val listing = s3.listObjectsV2(bucketName, prefix)
val files = listing.getObjectSummaries.asScala.map(_.getKey).filter(!_.split("/").last.startsWith("_"))
val filesSizeMap = collection.mutable.Map[String, Long]()
files.foreach(obj => {
val meta = s3.getObjectMetadata(new GetObjectMetadataRequest(bucketName, obj))
filesSizeMap += (obj -> meta.getContentLength)
})
filesSizeMap.toMap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment