-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathListEC2.py
More file actions
23 lines (17 loc) · 713 Bytes
/
ListEC2.py
File metadata and controls
23 lines (17 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import boto3
ec2 = boto3.resource('ec2')
print("Trying to find Running Instances")
instances = ec2.instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': ['running']}])
for instance in instances:
print(instance.id, instance.instance_type)
print("Trying to find Stopped Instances")
instances = ec2.instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': ['stopped']}])
for instance in instances:
print(instance.id, instance.instance_type)
print("Trying to find Terminated Instances")
instances = ec2.instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': ['terminated']}])
for instance in instances:
print(instance.id, instance.instance_type)