Search code examples
pythonamazon-web-servicesamazon-s3boto

Faster way to make S3 "folder hierarchy" than parsing of filenames?


I want to make a relatively basic tool to browse a bucket in S3 as a file hierarchy rather than simply a list of filenames with slashes in them.

Currently, I am using boto to get the list of keynames in a bucket and then parsing the keynames to make a nested dictionary of the "folders" and files. However, that process takes so long! Even just going through each key to get a list of all higher level folders takes 15+ minutes.

How do tools such as cyberduck give a list of folders so quickly?


Solution

  • Check this link: http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html

    listObjects() has a parameter called delimiter, which could be set to / and resulting list of objects will look exactly as a tree of files. I think this is what you're looking for.