There is an easier way. The Bucket object itself can act as an iterator, and it knows how to handle paginated responses. Thus, if there are more results available, he automatically takes them backstage. So, something like this should allow you to iterate over all the objects in your bucket:
for key in bucket:
If you want to specify a prefix and get a list of all keys starting with this prefix, you can do this as follows:
for key in bucket.list(prefix='foobar'):
Or, if you really want to create a list of objects, simply do the following:
keys = [k for k in bucket]
Note, however, that buckets can contain an unlimited number of keys, so be careful with this because it will list all the keys in memory.
source share