【发布时间】:2018-12-28 14:29:50
【问题描述】:
我只想从我的 S3 存储桶中检索 last_modified 键,使用 boto3 在特定前缀中。
# Get Today's date
today = datetime.date.today()
# Get Objects date
s3 = boto3.resource('s3',region_name=AWS_REGION)
bucket = s3.Bucket('xxx')
objs = bucket.objects.filter(Prefix='yyyy').limit(1)
def get_object_check_alarm():
try:
for obj in objs:
print(obj)
lastobjectdate = (obj.last_modified).date()
except botocore.exceptions.ClientError as e:
error_code = e.response['Error']['Code']
if error_code == '404':
print("There is no file")
# Compare with defined date
if today == lastobjectdate:
print(today)
print(lastobjectdate)
print("OK, lastest file comes from today")
else:
print(today)
print(lastobjectdate)
print("Mail sent")
使用此代码,当前结果不会输出最后修改的键。我尝试将limit() 增加到limit(10),但没有成功。
【问题讨论】:
-
我只看到你打印出 obj 本身,从来没有在 lastobjectdate 上。此外,如果您完全没有打印出来,这意味着您的 objs 实际上是空列表。检查您的前缀。
-
对不起,我已经添加了我的代码的缺失部分,这样会更容易理解
标签: python amazon-web-services amazon-s3 boto3