简体   繁体   English

如何使用 CloudShell 从按最大大小排序并在特定日期后修改的 S3 存储桶中获取 N 个文件?

[英]How to get N files from S3 bucket ordered by max size and modified after certain date using CloudShell?

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.虽然它搜索按最大大小排序的 5 个文件,但这些文件的最后修改时间可能在 2022 年 12 月 28 日之前,似乎部分查询只是被忽略了。

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.使用上面的命令,我希望看到在 2022 年 12 月 28 日或之后修改的按最大大小排序的文件。

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

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一段时间后我终于找到了解决方案,这将在 2022-12-28 之后修改的对象中按大小升序对 5 个对象进行排序

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM