-
Notifications
You must be signed in to change notification settings - Fork 3
/
terminate_instance.py
executable file
·37 lines (26 loc) · 1.01 KB
/
terminate_instance.py
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
34
35
36
37
#!/usr/bin/env python
import boto.ec2
import os
from optparse import OptionParser
import sys
import yaml
dirname = os.path.abspath(os.path.dirname(__file__))
config = yaml.load(open(os.path.join(dirname,"config.yaml"), "r"))
def getConnection():
return boto.ec2.connect_to_region(config['REGION'], \
aws_access_key_id = config['AWS_ACCESS_KEY_ID'],
aws_secret_access_key = config['AWS_SECRET_ACCESS_KEY'])
def terminateInstance(instanceId):
conn = getConnection()
conn.terminate_instances(instance_ids=[instanceId])
if __name__=='__main__':
parser = OptionParser()
parser.add_option('-i', '--instance-id', dest = 'instanceId',
type = "string",help = 'The Instance to be terminated')
(options, args) = parser.parse_args()
instanceId = options.instanceId
if not instanceId :
print "Please provide the instance-id to teardown it."
sys.exit(1)
print "Terminating Instance %s" % instanceId
terminateInstance(instanceId)