In my current project, I need to check the contents of my S3 bucket every 4 seconds for new files.
This script will run for about 3 hours each time the service is used, and by the end it will have about 2700 files on one prefix.
This is my function to list these files:
public function listFiles($s3Prefix, $limit, $get_after = ''){ $command = $this->s3Client->getCommand('ListObjects'); $command['Bucket'] = $this->s3_bucket; $command['Prefix'] = $s3Prefix; $command['MaxKeys'] = $limit; $command['Marker'] = $s3Prefix.'/'.$get_after; //command['Query'] = 'sort_by(Contents,&LastModified)'; $ret_s3 = $this->s3Client->execute($command); $ret['truncated'] = $ret_s3['IsTruncated']; $ret['files'] = $ret_s3['Contents']; return $ret; }// listFiles
I need to get files, sort by LastModified field, so I don't need to extract more than 2k files. Is there an additional parameter like
command['Query'] = 'sort_by(Contents,&LastModified)';
to add to php API?
---------- EDITED ------------
As indicated for Abhishek Mina’s answer, in the shell you can use
aws s3api list-objects --bucket "bucket-name" --prefix "some-prefix" --query "Contents[?LastModified>=\`2017-03-08\`]"
I am looking for how to implement this in PHP.
PHP API: https://github.com/aws/aws-sdk-php
source share