How can the developer modify the code to handle any number of returns?
Set max-keys in the ListObjectsV2 API call to the expected number of returned objects.
Set max-keys in the ListObjectsV2 API call to -1.
Run an S3 Select query to retrieve and list object keys from the bucket.
When applicable, repeat the ListObjectsV2 API call by using NextContinuationToken.
Explanations:
Themax-keysparameter specifies the maximum number of keys returned in a single call, but it cannot be set to an arbitrary expected number of returned objects, especially when the number of objects exceeds this value. This does not handle cases where more results are available.
Themax-keysparameter must be a positive integer. Setting it to-1is invalid and would result in an error.
S3 Select is used to query the contents of objects, not to list object keys. It is not designed to handle the listing of object keys in a bucket.
When the results exceed themax-keysvalue, the API returns aNextContinuationToken, which can be used to retrieve the next set of object keys. This process can be repeated until all objects have been listed. This is the correct method to handle large sets of results.