簡體   English   中英

在 S3 中查找特定文件的最后修改日期

[英]find last modified date of a particular file in S3

根據這個答案: 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,它可能不再使用。

在我的代碼片段中,我已經在使用 boto3 的s3_clients3_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 日期嗎?

你可以這樣做:

import boto3

s3 = boto3.resource("s3")
s3_object = s3.Object("your_bucket", "your_key")
print(s3_object.last_modified)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM