| Server IP : 52.25.153.185 / Your IP : 216.73.217.131 Web Server : Apache System : Linux ip-172-26-6-158 5.10.0-35-cloud-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64 User : daemon ( 1) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /usr/share/doc/python3-boto/examples/ |
Upload File : |
#!/usr/bin/python3
import sys
from optparse import OptionParser
import boto
from boto.ec2 import regions
def kill_instance(region, ids):
"""Kill an instances given it's instance IDs"""
# Connect the region
ec2 = boto.connect_ec2(region=region)
for instance_id in ids:
print("Stopping instance: %s" % instance_id)
ec2.terminate_instances([instance_id])
if __name__ == "__main__":
parser = OptionParser(usage="kill_instance [-r] id [id ...]")
parser.add_option("-r", "--region", help="Region (default us-east-1)", dest="region", default="us-east-1")
(options, args) = parser.parse_args()
if not args:
parser.print_help()
sys.exit(1)
for r in regions():
if r.name == options.region:
region = r
break
else:
print("Region %s not found." % options.region)
sys.exit(1)
kill_instance(region, args)