Yes, we can use the aws s3api...
to filter the keys that is older than 15 days by means of running below command (below returns expected result):
lastModifiedMax=`date -d "15 days ago" '+%Y-%m-%d'`
aws s3api list-objects --bucket $bucket --query "Contents[?LastModified<='${lastModifiedMax}'][].{object: Key}"
However, we want to use in python boto3, using this sample piece of the script -
Which is, we tried to replace this below lines
while True:
# The S3 API response is a large blob of metadata.
# 'Contents' contains information about the listed objects.
resp = s3.list_objects_v2(**kwargs)
for content in resp.get('Contents', []):
last_modified_date = content['LastModified']
if (
content['Key'].endswith(suffixes) and
last_modified_rule(last_modified_min, last_modified_date, last_modified_max)
):
yield content
With :
end_date = date.today() - timedelta(days=15)
for prefix in prefixes:
kwargs['Prefix'] = prefix
while True:
# The S3 API response is a large blob of metadata.
# 'Contents' contains information about the listed objects.
resp = s3.list_objects_v2(**kwargs)
for content in resp.get('Contents', ['?LastModified<='+str(end_date)]):
yield content
The above changes did not give expected result, means, returned "whole" keys (whole timetamp).
Please advise what is wrong.
Yes, we can use the aws s3api...
to filter the keys that is older than 15 days by means of running below command (below returns expected result):
lastModifiedMax=`date -d "15 days ago" '+%Y-%m-%d'`
aws s3api list-objects --bucket $bucket --query "Contents[?LastModified<='${lastModifiedMax}'][].{object: Key}"
However, we want to use in python boto3, using this sample piece of the script - https://stackoverflow/a/53877685/27921578
Which is, we tried to replace this below lines
while True:
# The S3 API response is a large blob of metadata.
# 'Contents' contains information about the listed objects.
resp = s3.list_objects_v2(**kwargs)
for content in resp.get('Contents', []):
last_modified_date = content['LastModified']
if (
content['Key'].endswith(suffixes) and
last_modified_rule(last_modified_min, last_modified_date, last_modified_max)
):
yield content
With :
end_date = date.today() - timedelta(days=15)
for prefix in prefixes:
kwargs['Prefix'] = prefix
while True:
# The S3 API response is a large blob of metadata.
# 'Contents' contains information about the listed objects.
resp = s3.list_objects_v2(**kwargs)
for content in resp.get('Contents', ['?LastModified<='+str(end_date)]):
yield content
The above changes did not give expected result, means, returned "whole" keys (whole timetamp).
Please advise what is wrong.
Share Improve this question edited Nov 18, 2024 at 17:48 Hari Addepalli asked Nov 18, 2024 at 17:47 Hari AddepalliHari Addepalli 33 bronze badges1 Answer
Reset to default 0never mind - debugged/researched, we can achieve by means of this
for content in resp.get('Contents', []):
if (
content['Key'] and content['LastModified'] <= datetime.now().astimezone() - timedelta(days=15)
):
yield content
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745603532a4635541.html
评论列表(0条)