Search code examples
pythonpaginationboto3aws-organizations

<botocore.paginate.PageIterator object at 0x0000011CF0AC70C8> Is my paginator ill? What iam doing wrong?


I can´t solve my annoying problem, here is my code

import boto3
org = boto3.client('organizations')

paginator = org.get_paginator('list_policies')
page_iterator = paginator.paginate(Filter='SERVICE_CONTROL_POLICY', PaginationConfig={'MaxItems': 100})
print(page_iterator)

I would like to see the result but I get the following

<botocore.paginate.PageIterator object at 0x0000011CF0AC70C8>

Has anyone an idea where iam stuck here?


Solution

  • Boto3 paginators are generator-like objects. This means they don't contain all elements at once in printable form, but will produce next element in sequence when called.

    So in order to print its contents you need only small addition of a loop (or list comprehension) in your code:

    page_iterator = paginator.paginate(Filter='SERVICE_CONTROL_POLICY', PaginationConfig={'MaxItems': 100})
    for i in page_iterator:
        print(i)
    

    https://boto3.amazonaws.com/v1/documentation/api/latest/guide/paginators.html