Skip to content

Commit 0289b93

Browse files
committed
UpDate
1 parent d22f098 commit 0289b93

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

AWS_Boto/boto_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
aws_access_id = <YOUR_KEY_ID>
2+
aws_access_key = <YOUR_ACCESS_KEY>

AWS_Boto/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This is public code for educational use only.
2+
# Please check what instances are you terminating
3+
# Before terminating, the script checks match to "key" of the instances and then if running, terminate.
4+
# Once temrinated the data may be lost!
5+
6+
from boto import ec2
7+
import boto3
8+
import boto_config_orig as boto_config
9+
from pprint import pprint
10+
11+
aws_access_id = boto_config.aws_access_id
12+
aws_access_key = boto_config.aws_access_key
13+
ec21 = boto3.resource('ec2', boto_config.aws_region)
14+
15+
termination_list_instances = []
16+
17+
ec2conn = ec2.connection.EC2Connection(region=ec2.get_region(boto_config.aws_region))
18+
reservations = ec2conn.get_all_instances()
19+
instances = [i for r in reservations for i in r.instances]
20+
21+
for i in instances:
22+
if str(i.key_name) == "<SPECIFIC KEY ONLY>" and str(i._state) != "terminated(48)": #CHECK FOR STATUS RUNNING
23+
termination_list_instances.append(str(i.id))
24+
25+
if not termination_list_instances:
26+
print("No instance to be terminated!")
27+
quit()
28+
29+
else:
30+
try:
31+
for i in termination_list_instances:
32+
print("Terminating this instance: " + i)
33+
ec21.instances.filter(InstanceIds=[i]).terminate() #real terminator
34+
35+
except Exception as e:
36+
print(e)
File renamed without changes.

0 commit comments

Comments
 (0)