我试图从 s3 存储桶中获取最后修改的文件。我尝试了不同的方法来检索它。但它总是向我显示目录中的所有文件。有人可以请教吗?
def last_updated_file(self):
bucket_name = "test-bucket"
conn = boto3.session.Session(profile_name="profile-name")
s3 = conn.resource('s3')
test_buc = s3.Bucket(bucket_name)
for x in test_buc.objects.filter(Prefix='test-file/files/'):
result = x.last_modified
print("Result is :", result)
我得到的输出是
Result is : 2022-01-18 15:52:48+00:00
Result is : 2022-01-18 15:54:11+00:00
Result is : 2022-01-18 15:54:12+00:00
Result is : 2022-01-24 17:40:24+00:00
我只需要最后一个文件“2022-01-24 17:40:24+00:00”