AWS SDK for Java: how to to List Objects in S3 Bucket with Specific Prefix and Pagination
I'm using the AWS SDK for Java (version 1.11.1000) to list objects in an S3 bucket with a specific prefix. However, I'm working with unexpected behavior where the `listObjectsV2` method does not return all the objects when using pagination. I have a bucket named `my-bucket` and I'm trying to list objects that start with the prefix `images/`. Hereβs the relevant code Iβm using: ```java AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(Regions.US_EAST_1) .build(); ListObjectsV2Request request = new ListObjectsV2Request() .withBucketName("my-bucket") .withPrefix("images/") .withMaxKeys(100); ListObjectsV2Result result; do { result = s3Client.listObjectsV2(request); for (S3ObjectSummary objectSummary : result.getObjectSummaries()) { System.out.println("- " + objectSummary.getKey()); } request.setContinuationToken(result.getNextContinuationToken()); } while (result.isTruncated()); ``` The question I'm working with is that when I execute this code, it returns only a subset of the objects, even though I know there are more objects matching the prefix. Specifically, it lists about 50 objects but I expect around 200. I checked the AWS Management Console, and I can see all of them without any scenario. The `isTruncated()` method returns true, so I try to set the continuation token, but it seems like Iβm missing something. I've also verified that there are no permissions issues with my IAM role, as I can access all objects when manually checking in the console. Additionally, I've tried increasing `withMaxKeys` to 200 but it still results in the same number of objects listed. Is there a limit on how many times I can paginate, or is there something specific with the prefix that could be causing this behavior? Any insights would be greatly appreciated!