I need to get the list of object keys sorted by their last modified timestamp from S3 prefix. Since there is a lot of objects present, and I know I am interested in certain certain number of objects that have been recently modified, what would be the way to do that in boto3?
Sorting all the objects on the client side as I currently do takes very long time:
def get_last_modified(obj):
return int(obj.last_modified.strftime("%s"))
def process(prefix):
input_bucket = boto3.resource("s3").Bucket("my-test-bucket")
objects = list(input_bucket.objects.filter(Prefix=prefix))
sorted_objects = sorted(objects, key=get_last_modified, reverse=True)