Put "sort_by" in aws-php-sdk ListObjects

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

+5
source share
1 answer

I don’t know if they have something to sort the objects based on LastModified , but you can query and filter the objects in the LastModified column. This is what you can use to filter all files changed over time aws s3api list-objects --bucket "bucket-name" --prefix "some-prefix" --query "Contents[?LastModified>=\`2017-03-08\`]"

This is for a shell that might have something similar for php.

+1
source

Source: https://habr.com/ru/post/1264701/


All Articles