如何按修改日期列出Amazon S3存储桶内容? [英] How list Amazon S3 bucket contents by modified date?
问题描述
在大多数情况下,由于我们很难在其中存储数据,因此我们将文件加载到一个普通的S3存储桶中.
Most of the time it happens that we load files in a common S3 bucket due to which it becomes hard to figure out data in it.
如何查看在特定日期上传的对象?
How can I view objects uploaded on a particular date?
推荐答案
一种解决方案可能是使用 s3api
.如果您的对象少于1000个,那么它很容易工作,否则您需要进行分页.
One solution would probably to use the s3api
. It works easily if you have less than 1000 objects, otherwise you need to work with pagination.
s3api
可以列出所有对象,并且具有s3中导入的键的lastmodified
属性的属性.然后可以对它进行排序,查找日期之后或之前的文件,匹配日期...
s3api
can list all objects and has a property for the lastmodified
attribute of keys imported in s3. It can then be sorted, find files after or before a date, matching a date ...
运行该选项的示例
-
给定日期的所有文件
all files for a given date
DATE=$(date +%Y-%m-%d)
aws s3api list-objects-v2 --bucket test-bucket-fh --query 'Contents[?contains(LastModified, `$DATE`)]'
特定日期之后的所有文件
all files after a certain date
export YESTERDAY=`date -v-1w +%F`
aws s3api list-objects-v2 --bucket test-bucket-fh --query 'Contents[?LastModified > `$YESTERDAY`]'
s3api将返回少量元数据,因此您可以过滤特定元素
s3api will return a few metadata so you can filter for specific elements
DATE=$(date +%Y-%m-%d)
aws s3api list-objects-v2 --bucket test-bucket-fh --query 'Contents[?contains(LastModified, `$DATE`)].Key'
这篇关于如何按修改日期列出Amazon S3存储桶内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!