Created
March 4, 2022 09:27
-
-
Save wrouesnel/03031385a5f02dd2c6484ac99b4daa88 to your computer and use it in GitHub Desktop.
botoresults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def boto_results(key, fn, *args, **kwargs): | |
result = [] | |
next_token = None | |
while True: | |
r = fn(*args, **kwargs) | |
next_token = r.get("NextToken") | |
value = r[key] | |
if isinstance(value, (str, bytes)): | |
result.append(value) | |
elif isinstance(value, Mapping): | |
result.append(value) | |
else: | |
result.extend(value) | |
if next_token is None: | |
break | |
kwargs.update({"NextToken": next_token}) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment