I need some assistance with filtering S3 results using AWS SDK for PHP v3 and JMESPath. Filtering by a number is not working with the PHP SDK as JMESPath documention and online examples suggest.
<?php
// test.php
use Aws\S3\S3Client;
// Create S3 client
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
$bucket = 'my-bucket-name';
$prefix = 'path/to/my/objects';
// Call list-objects-v2
$awspaginator = $s3->getPaginator('ListObjectsV2', [
'Bucket' => $bucket,
'Prefix' => $prefix
]);
// Apply filter to paginator
$jmes = "reverse(Contents[?Size>`0`].{Key: Key, Date: LastModified, Size: Size}) | [-10:]";
$results = $awspaginator->search($jmes);
// Echo results
$i = 0;
foreach ($results as $result) {
echo "\nResult: " . print_r($result);
$i++;
}
echo "\nCount: " . $i . PHP_EOL;
?>
This outputs Count: 0
But if I replace Size> `0` with StorageClass=='STANDARD' I get the 10 most recent objects as expected.
I've attempted the following Size expressions without any luck.
Size>0// returns error: unexpected number tokenSize>'0'// succeeds: returns no resultsSize>`0`// succeeds: returns no resultsSize!=`0`// returns results but does not filter out zero size objectsSize!=\"0\"// returns results but does not filter out zero size objects
Note that the s2api query works just fine so this seems to be something to do with the PHP SDK Search method.
--bucket my-bucket-name \
--prefix path/to/my/objects \
--query "reverse(Contents[?Size>\`0\`].{Key: Key, Date: LastModified, Size: Size}) | [-10:]"
Any help is appreciated!