`buck.objects.each` is going to scan the entire bucket, which will be very slow for large buckets, perhaps on the order of hours for people who store lots of data. Instead, you want to use a prefix-based search of the bucket, which is supported natively by the S3 API.

See (this method)[https://github.com/mortardata/luigi/blob/master/luigi/s3.py#L143] for a good starting point, albeit in python. You basically are doing the same thing, except you want to copy from s3 to local instead of s3-to-s3. You'll need to use the same strategy to determine whether you're working with a directory or file, and the same strategy as that code to find directories.