Fetching S3 objects filtered by date

0

I have a requirement for a python script running periodically, which checks how many objects were added to a specific S3 bucket during the last 24h. At the moment, the script has to fetch all objects from the bucket filtered by the prefix, and then filter them by date on the client side. Unfortunately, this takes over an hour, simply because we have so many objects in the bucket. I would like to find out if it's possible to fetch from S3 bucket only the objects from last 24h, which would massively speed up the script. I did not find such an option for the aws cli command, which means that the boto3 framework I use won't have it either. I have been looking into S3 inventory too, but it's same in this case - only prefix can be used to filter the objects, not a date. In my case, I cannot change naming format for the objects, and at the moment they don't include date. Is there I way of doing this that I missed?

kmbzdyk
已提問 3 個月前檢視次數 447 次
2 個答案
3

Hi,

I would suggest a different approach: implement a Lambda trigger on S3 updates. and use this Lambda to record the changes in a S3 file. So, you'll just have to record the changes in a file from this Lambda. Then, downloading this single inventory file will give you all changes at once.

This doc gives you details about S3 triggers with Lamdda: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

Best,

Didier

profile pictureAWS
專家
已回答 3 個月前
profile picture
專家
已審閱 3 個月前
2

Hello.

If you cannot change object names, I don't think you can filter using S3's "ListObjectsV2" API.
So, as an alternative, how about registering the object path and creation date in DynamoDB when the S3 object is created?
By setting an S3 event trigger, you can run Lambda when an object is created.
By using Lambda to register object information to DynamoDB, you can easily perform aggregation.
https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

profile picture
專家
已回答 3 個月前
profile picture
專家
已審閱 3 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南