-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow NextToken
to be None
#959
Comments
The issue is that |
@JordonPhillips there are not paginators for all operations. Only: I support @tmshn suggestion of allowing None for nextToken. |
The value It could be like this (an example from PyGithub): What do you say, @JordonPhillips, @ryguyrg ? |
Because ended up here searching for |
@gmanfunky not always, you can try ssm api for get_parameters_by_path
Now there is a pagination supported in the latest release of botocore but I am using AWS Lambda which lags behind in updating the SDK. I know I can push the latest botocore package but I am trying to keep my Lambda slim for cold start times. |
It would be nice to have a Failing that, the code in the example can be simplified: cw = boto3.client('events')
extraArgs = {}
while True:
rulesPage = cw.list_rules(**extraArgs)
for rule in rulesPage['Rules']:
# do something
if 'NextToken' in rulesPage:
extraArgs['NextToken'] = rulesPage['NextToken']
else:
break it isn't pretty, but it allows you to avoid repeating |
For anyone else reading this, i went a similar route but handled as a function to manage it. ORG=boto3.client('organizations')
def get_org_accounts(**args):
response = ORG.list_accounts(**args)
accounts = response["Accounts"]
if "NextToken" in response:
args['NextToken'] = response['NextToken']
accounts += get_org_accounts(**args)
return accounts also, there is a new thing you can do with while loops as of python 3.8 ORG=boto3.client('organizations')
response = ORG.list_accounts()
accounts = response["Accounts"]
while token := response.get('NextToken'):
response = ORG.list_accounts(NextToken=token)
accounts.extend(response["Accounts"]) |
Summary
In many clients,
NextToken
parameter is used to iterate over all resources, with saywhile
loop.However, you can't pass
NextToken
param for the first fetch, which makes codes complicated.I believe allowing
NextToken
to beNone
will solve this.Example
Here's well-work example to get all cloudwatch alarms.
If
NextToken
can beNone
, the code can be simpler:Currently, above code will get following error
How to fix
For me, botocore is too complicated to make some changes, but I found following code may have something to do with the issue.
https://github.com/boto/botocore/blob/develop/botocore/client.py#L547
One idea is adding following lines:
If you tell me where to fix, I feel no reluctance in making a pull request.
My envoironment
The text was updated successfully, but these errors were encountered: