Q: List objects with AWS S3 SDK for Java 2.x I have a bucket (logs) in Amazon S3 (us-east-1) with, unsurprisingly, logs, partitioned by application and date:
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

I want to list all the objects (logs) for a particular date, month, year…
How do I do that with AWS SDK for Java 2.x?

A: New SDK makes it easy to work with paginated results:
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());
    }
}

