0

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
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Atihska
  • 4,803
  • 10
  • 56
  • 98

1 Answers1

3

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']
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Thanks John, I figured this out using this: https://stackoverflow.com/questions/39201093/how-to-use-boto3-pagination. But I will mark your response as answer as well. Thanks for replying. – Atihska Jul 26 '18 at 22:04