且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Boto3 S3,按上次修改对桶进行排序

更新时间:2023-11-27 09:37:58

我对@helloV 在下面发布的内容做了一些小改动.它不是 100% ***,但它完成了工作,但目前 boto3 存在限制.

I did a small variation of what @helloV posted below. its not 100% optimum, but it gets the job done with the limitations boto3 has as of this time.

s3 = boto3.resource('s3')
my_bucket = s3.Bucket('myBucket')
unsorted = []
for file in my_bucket.objects.filter():
   unsorted.append(file)

files = [obj.key for obj in sorted(unsorted, key=get_last_modified, 
    reverse=True)][0:9]