Lets say I'm iterating over my bucket every hour to check if new objects were added. Currently I'm doing it by iterating over all objects and checking if any have modification time newer than the latest in previous iteration, which is inefficient in terms of runtime.
My code looks something like this:
DateTime lastDateTime = DateTime.MinValue;
if (checkpoint != null)
lastDateTime = checkpoint;
List<S3Object> newFiles = new List<S3Object>();
ListObjectsV2Request request = new ListObjectsV2Request {
BucketName = myBucketName };
ListObjectsV2Response response;
do
{
response = await s3Client.ListObjectsV2Async(request);
// save only new object to list
newFiles.AddRange(response.S3Objects.Where(x => x.LastModified > lastModificationTime));
request.ContinuationToken = response.NextContinuationToken;
} while (response.IsTruncated);
newFiles = newFiles.OrderByDescending(x => x.LastModified).ToList();
checkpoint = newFiles[0].LastModified;
Is there an effective way to do this without having to always ask S3 for a list of all the objects and then filtering them out?