【发布时间】:2021-12-08 23:03:23
【问题描述】:
根据这个答案:https://stackoverflow.com/a/9688496/13067694
>>> import boto
>>> s3 = boto.connect_s3()
>>> bucket = s3.lookup('mybucket')
>>> for key in bucket:
print key.name, key.size, key.last_modified
index.html 13738 2012-03-13T03:54:07.000Z
markdown.css 5991 2012-03-06T18:32:43.000Z
>>>
我可以这样做来查找 last_modified 日期。在这里,他们使用的是 boto.connect_s3。但我无法在 AWS Lambda 上导入 boto,它可能已不再使用。
在我的代码 sn-p 中,我已经在使用 boto3 的 s3_client 和 s3_resource。我尝试了最后一行来查找存储桶中特定文件的最后修改日期:
s3 = boto3.client('s3')
lst = s3.list_objects(Bucket='testunzipping')['Contents']
s3_resource = boto3.resource('s3')
bucket = s3_resource.Bucket('testunzipping')
s3.download_file('testunzipping','DataPump_10000838.zip','/tmp/DataPump_10000838.zip')
lastModified = bucket['DataPump_10000838.zip'].last_modified
但它给了我一个错误"errorMessage": "'s3.Bucket' object is not subscriptable"
是否仍然可以单独使用 boto3.client 和资源找到 last_modified 日期?另外,我还使用 s3.download_file 下载文件。我不能在下载时只提取 last_modified 日期吗?
【问题讨论】:
标签: python amazon-web-services amazon-s3 boto3 boto