I'm trying to get a complete list of instances available in a region. The code will iterate over a number of pages but stops short with an error:
Traceback (most recent call last):
File "list_available_instance_offerings.py", line 29, in <module>
marker = page_iterator['Marker']
TypeError: 'PageIterator' object is not subscriptable
How can I iterate over all of the pages without erroring prematurely?
Here's my script:
import sys
import boto3
ec2 = boto3.client("ec2")
marker = None
while True:
paginator = ec2.get_paginator('describe_instance_type_offerings')
page_iterator = paginator.paginate(
LocationType='availability-zone',Filters=[{'Name': 'location', 'Values':['us-east-1a']}],
PaginationConfig={
'PageSize': 50,
'StartingToken': marker})
for page in page_iterator:
offerings = page['InstanceTypeOfferings']
for offer in offerings:
print(offer['InstanceType'])
try:
marker = page_iterator['Marker']
except KeyError:
sys.exit()