如何解决如何使用 Python boto3 获取 s3 存储桶中超过 60 天的文件/对象计数?
我想获取超过 60 天的所有对象的计数?有什么方法可以执行查询或任何 python boto3 方法来获取所需的输出?
解决方法
这是来自 S3 存储桶中超过 60 天的文件或对象的代码。
import json
import boto3
import datetime
import time
from time import mktime
client = boto3.client('s3')
response = client.list_objects(Bucket='angularbuildbucket')
print(response)
today_date_time = datetime.datetime.now().replace(tzinfo=None)
print(today_date_time)
for file in response.get("Contents"):
file_name =file.get("Key")
modified_time = file.get("LastModified").replace(tzinfo=None)
difference_days_delta = today_date_time - modified_time
difference_days = difference_days_delta.days
print("difference_days---",difference_days)
if difference_days > 60:
print("file more than 60 days older : - ",file_name)
注意:确保您在本地运行此代码以设置 AWS CLI 环境并正确传递配置文件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。