-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance-killer.py
More file actions
33 lines (26 loc) · 886 Bytes
/
instance-killer.py
File metadata and controls
33 lines (26 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
import boto3
def main (instance_ids) :
print("INSTANCE KILLER\n")
ec2_res = boto3.resource('ec2')
for instance_id in instance_ids:
instance = ec2_res.Instance(instance_id)
print(f"Terminating instance {instance_id} ...")
instance.terminate() # Terminate the instance
instance.wait_until_terminated()
instance.reload() # Update instance data
print(f"Instance {instance.id} succesfully terminated !")
print(f"State: {instance.state['Name']}")
print()
return 0
def usage(exitstatus):
print(
"Usage: python3 instance_killer.py <instance1_id> <instance2_id> <instance3_id>..."
)
sys.exit(exitstatus)
if __name__ == "__main__":
if sys.argv[1] == "-h":
usage(0)
if len(sys.argv) <= 1 :
usage(1)
main(sys.argv[1:])