Skip to content

Instantly share code, notes, and snippets.

@snarkyboojum
Created January 21, 2020 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snarkyboojum/a03a32ea5492f97f33e9c5f0be581499 to your computer and use it in GitHub Desktop.
Save snarkyboojum/a03a32ea5492f97f33e9c5f0be581499 to your computer and use it in GitHub Desktop.
List all EC2 instances in a region
#!/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