Created
January 21, 2020 07:57
-
-
Save snarkyboojum/a03a32ea5492f97f33e9c5f0be581499 to your computer and use it in GitHub Desktop.
List all EC2 instances in a region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import boto3 | |
ec2 = boto3.client('ec2', region_name='us-east-1') | |
instance_types = [] | |
types = ec2.describe_instance_types() | |
instance_types.extend(types['InstanceTypes']) | |
next_token = '' | |
if 'NextToken' in types: | |
next_token = types['NextToken'] | |
while next_token != '': | |
types = ec2.describe_instance_types(NextToken=next_token) | |
instance_types.extend(types['InstanceTypes']) | |
if 'NextToken' in types: | |
next_token = types['NextToken'] | |
else: | |
next_token = '' | |
for i in instance_types: | |
print(i['InstanceType']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment