nextToken in AWS boto3 Request
January 17, 2025•112 words
In one of my projects, I was trying to obtain a list of all available files in an AWS s3 bucket, which is done through an API call through boto3
.
However, I noticed that the returned list isn't complete, and that there is an additional field nextToken
.
A quick search returns this StackOverflow page that solves my problem. Basically, the API may not return the complete result when it is too long. Instead, it returns a partial result + nextToken
. You can use nextToken
in the next API call to continue retrieving the remainder of the result.
Obviously, a while loop would suffice for retrieving the full list of files that I wanted.