Open
Description
Describe the bug
When using boto3 to iterate an S3 bucket with a Delimiter, MaxItems only counts the keys, not the prefixes. So if you have a bucket with only prefixes, MaxItems will never stop searching and may take unbounded time.
Steps to reproduce
Set up a bucket with 20000 keys of the form result1/results.txt ... result20000/results.txt
Run this code:
import boto3
s3 = boto3.client('s3')
paginator = s3.get_paginator('list_objects_v2')
for result in paginator.paginate(Bucket='mybucket', Delimiter='/', PaginationConfig={'MaxItems': 2000}):
for prefix in result.get('CommonPrefixes', []):
print("prefix {}".format(prefix['Prefix']))
for key in result.get('Contents', []):
print("key {}".format(key['Key'])
Expected behavior
The above program should return a maximum of 2000 keys. It actually returns all 20,000 keys, because MaxItems doesn't count prefixes.