sorting an S3 bucket by last updated date - Hack The Tech - Latest News related to Computer and Technology

logo

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, November 15, 2023

demo-image

sorting an S3 bucket by last updated date

According to https://stackoverflow.com/a/65675842/569976 , you can use the AWS S3 CLI client to sort the results of a list-objects-v2 by the last modified date, as follows:

aws s3api list-objects --bucket bucketname --query 'sort_by(Contents, &LastModified)[-1].Key' --output text

My question is... how do you do that with the PHP client / Aws\S3\S3Client::listObjects?

https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#listobjects mentions a bunch of options you can pass to it and none of them are "query":

$result = $client->listObjects([
    'Bucket' => '<string>', // REQUIRED
    'Delimiter' => '<string>',
    'EncodingType' => 'url',
    'ExpectedBucketOwner' => '<string>',
    'Marker' => '<string>',
    'MaxKeys' => <integer>,
    'OptionalObjectAttributes' => ['<string>', ...],
    'Prefix' => '<string>',
    'RequestPayer' => 'requester',
]);

Is it just not possible with the PHP API client?



source https://stackoverflow.com/questions/77482604/sorting-an-s3-bucket-by-last-updated-date

No comments:

Post a Comment