I just kind of figured out how to use the nextToken in boto3. The API call I am making I should expect about 300 entries. I only get 100. I know I need to loop through the next token but I am struggling on how to do that. I am new to the python army.
def myservers():
response = client.get_servers(maxResults=100,)
additional = client.get_servers(nextToken=response['nextToken'])
this little snipit will give me the first 50 plus the first 'nextToken' for a total of 100 items. Clearly I need to iterate over and over to get the rest. I am expecting 300 plus items.
I would just do a simple while loop:
response = client.get_servers()
results = response["serverList"]
while "NextToken" in response:
response = client.get_servers(NextToken=response["NextToken"])
results.extend(response["serverList"])
I used the suggestion here:
https://github.com/boto/botocore/issues/959#issuecomment-429116381
You have to keep calling client.get_servers() passing in the NextToken.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With