skip to Main Content

I tried to use this command:

aws s3api list-objects-v2 --bucket BUCKETNAME --query 'Contents[?LastModified>=2022-12-28].Key && sort_by(Contents, &Size)[-5:]'

And while it searches for 5 files ordered by max size, the files may be last modified before 2022-12-28, it seems that part of the query is just being ignored.

What am I doing wrong?

With the command above I expected to see files ordered by max size that were modified AFTER or on 2022-12-28.

2

Answers


  1. Chosen as BEST ANSWER

    After some time I finally found the solution, this will get 5 objects sorted in ascending order of size among objects modified after 2022-12-28

    aws s3api list-objects-v2 --bucket BUCKETNAME --query 'sort_by(Contents[?LastModified>=`2022-12-28`], &Size)[-5:]'


  2. You’re correct that something seems to be wrong with the result when both time check and sort queries are included.

    You can use this command which filters by date correctly and then uses the terminal sort to sort by size.

    aws s3api list-objects-v2 --bucket BUCKETNAME --query 'Contents[?LastModified > `2022-12-28`].{Key: Key, Size: Size}' --output text | sort -k2 -n

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search