Created
January 28, 2017 15:30
-
-
Save jason-callaway/614208e770865e6c4780c2e7a4ca8a1f to your computer and use it in GitHub Desktop.
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
#!/bin/python | |
import boto.ec2 | |
whitelist = ["id1", "id2", "id3"] | |
conn = boto.ec2.connect_to_region("us-east-1", | |
aws_access_key_id="redacted", | |
aws_secret_access_key="redacted") | |
reservations = conn.get_all_reservations() | |
running_instances = [] | |
for r in reservations: | |
for i in r.instances: | |
if i.state == "running": | |
if i.id not in whitelist: | |
running_instances.append(i.id) | |
conn.stop_instances(instance_ids=running_instances) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment