S3- boto-list files in the basket by boot time

I need to download 100 latest files from the s3 server every hour.

bucketList = bucket.list(PREFIX) 

The above code creates a list of files, but it does not depend on the time the files were downloaded, since it is written off by the file name?

I can do nothing with the file name. It is given randomly.

Thanks.

+4
source share
2 answers

How big is the list? You can sort the list by the "last_modified" attr key

 orderedList = sorted(bucketList, key=lambda k: k.last_modified) keysYouWant = orderedList[0:100] 

If your list is HUGE, this may be ineffective. Check the inline documents for the list () function in the boto.s3.bucket.Bucket file.

+9
source

My reading The documentation for objects in the list of objects suggests that the objects are always listed in alphabetical order (by object key).

If you code the creation time of each object in the object key, you can achieve what you want.

+2
source

Source: https://habr.com/ru/post/1379172/


All Articles