我在亚马逊S3 (us-east-1)中有一个存储桶(logs),其中包含按应用程序和日期分区的日志,这并不奇怪:
logs
├── peacekeepers
│ └── year=2018
│ ├── month=11
│ │ ├── day=01
│ │ ├── day=…
│ │ └── day=30
│ └── month=12
│ ├── day=01
│ ├── day=…
│ └── day=19
│ ├── 00:00 — 01:00.log
│ ├── …
│ └── 23:00 — 00:00.log
├── rep-hunters
├── retro-fans
└── rubber-duckies我想列出特定日期、月份、年份…的所有对象(日志
如何使用AWS SDK for Java 2.x实现这一点
发布于 2018-12-20 02:01:24
新的SDK使得处理分页结果变得很容易:
S3Client client = S3Client.builder().region(Region.US_EAST_1).build();
ListObjectsV2Request request =
ListObjectsV2Request
.builder()
.bucket("logs")
.prefix("peacekeepers/year=2018/month=12")
// .prefix("peacekeepers/year=2018/month=12/day=19")
.build();
ListObjectsV2Iterable response = client.listObjectsV2Paginator(request);
for (ListObjectsV2Response page : response) {
for (S3Object object : page.contents()) {
// Consume the object
System.out.println(object.key());
}
}https://stackoverflow.com/questions/53856862
复制相似问题