2022. 12. 4.

Using paginator in boto3


How to convert codes for using paginator

### no paginations code
  1. for region in regions:
  2.     resource = boto3.client('resourcegroupstaggingapi', region_name=region)
  3.     res = resource.get_resources(ResourceTypeFilters=resource_type_filters)
  4.     list_items(res)

    

### using paginator code
  1. for region in regions:
  2.     resource = boto3.client('resourcegroupstaggingapi', region_name=region)
  3.     paginator = resource.get_paginator('get_resources')  # parameter is 'method name' which is LINE3 of above code 
  4.     response_iterator = paginator.paginate(ResourceTypeFilters=resource_type_filters) #Passing parameter is same with   LINE3 in above code
  5.     for page in response_iterator:
  6.         list_items(page)