4

I'm currently using the latest version (V3) of the AWS PHP SDK. I want to get all object keys from my bucket from the last X number of days. I'm trying to use the search function as described here, which uses JMESPath expressions.

This comment seemed very promising, but when I try the following:

$results = $s3Client->getPaginator('ListObjectsV2', ['Bucket' => 'testbucket', 'Prefix' => 'someprefix']);

foreach ($results->search('Contents[?LastModified>=`2017-01-01`][].{Key: Key}') as $result) {
    echo $result;
}

I get nothing, even though I have objects newer than this date. However, when I try, for example:

foreach ($results->search('Contents[?Size>=`1024`][].{Key: Key}') as $result) {
    echo $result;
}

It seems to work and I get results as expected. My keys are in the general format of 20170120-211752-24-file.csv, so I suppose I can strip the date before the first hyphen, loop through all keys, and compare that way, but ideally I'd not want to pull potentially thousands of objects and do that after the search.

Any ideas?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
ShaneOH
  • 1,454
  • 1
  • 17
  • 29

0 Answers0