Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Last active August 29, 2015 14:17
Show Gist options
  • Save wehappyfew/a75405c3f834a12c7e55 to your computer and use it in GitHub Desktop.
Save wehappyfew/a75405c3f834a12c7e55 to your computer and use it in GitHub Desktop.
def delete_instances(instance_tag="your_tag" , instance_state="stopped"):
"""
The function
1. filters all the instances by tag and instance-state
2. terminates/deletes the filtered instances (irreversible action!!!)
"""
reserves = conn.get_all_instances( filters={"tag-value":instance_tag , "instance-state-name":instance_state} )
for r in reserves:
for instance in r.instances:
instance.terminate()
print "OK! instance -"+str(instance.id)+"- was deleted. \n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment