Created
March 13, 2018 17:55
-
-
Save sudharsans/f7b16387f64d6949191268c55a19b148 to your computer and use it in GitHub Desktop.
Boto3 API - example using paginator
This file contains hidden or 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
import boto3 | |
cloudtrail = boto3.client('cloudtrail') | |
paginator = cloudtrail.get_paginator('lookup_events') | |
StartingToken = None | |
page_iterator = paginator.paginate( | |
LookupAttributes=[{'AttributeKey':'EventName','AttributeValue': 'RunInstances'}], | |
PaginationConfig={'PageSize':10, 'StartingToken':StartingToken }) | |
for page in page_iterator: | |
for event in page["Events"]: | |
print(event["EventName"],event["EventTime"]) | |
try: | |
token_file = open("token","w") | |
token_file.write(page["NextToken"]) | |
StartingToken = page["NextToken"] | |
except KeyError: | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment