Last active
December 11, 2015 03:39
-
-
Save ytjohn/4539841 to your computer and use it in GitHub Desktop.
find and terminate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import boto | |
import boto.ec2 | |
import requests | |
from requests.auth import HTTPBasicAuth | |
def find_ec2_nodes(name, c): | |
''' | |
Compares entered address against all instances to find instance ID | |
''' | |
# c = boto.ec2.connection.EC2Connection(AWS_ACCESS,AWS_SECRET) | |
instances = c.get_all_instances() | |
# ignore terminated instances. | |
for i in instances: | |
n = i.instances[0].public_dns_name | |
if n == name: | |
return i.instances[0] | |
def terminate_Instances(instance_id, c): | |
''' | |
stops, terminates, and deletes instances and volumes | |
''' | |
# c = boto.ec2.connection.EC2Connection(AWS_ACCESS,AWS_SECRET) | |
c.stop_instances(instance_id) | |
c.terminate_instances(instance_id) | |
if __name__ == "__main__": | |
AWS_ACCESS = 'accesskey' | |
AWS_SECRET = 'supersecret' | |
c = boto.ec2.connection.EC2Connection(AWS_ACCESS,AWS_SECRET) | |
print find_ec2_nodes('ec2-1-2-3-4.compute-1.amazonaws.com', c) | |
# terminate: | |
# terminate_Instances(instance.id, AWS_ACCESS, AWS_SECRET) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment