Reputation: 5126
How can I paginate results for iterating over aws pricing api to get prices?
Here is what I tried but getting error for no attribute 'getitem'
pricing = boto3.client('pricing', region_name='us-east-1')
token = ''
paginator = pricing.get_paginator('get_products')
while True:
response = paginator.paginate(
ServiceCode='AmazonEC2',
Filters=[
{'Type': 'TERM_MATCH', 'Field': 'operatingSystem', 'Value': 'Linux'},
{'Type': 'TERM_MATCH', 'Field': 'location', 'Value': 'US West (Oregon)'}
],
PaginationConfig={
'MaxItems':100,
'PageSize':100,
'StartingToken':token
}
)
token = response['NextToken']
print response.result_keys
Upvotes: 0
Views: 1489
Reputation: 269826
It would appear you need to iterate using NextToken
.
Here is an extract from Paginating AWS API Results using the Boto3 Python SDK – aws advent:
next_token = '' # variable to hold the pagination token
while next_token is not None:
results = pricing.get_products(..., NextToken=next_token)
next_token = results['NextToken']
Upvotes: 3