Skip to content

Instantly share code, notes, and snippets.

@thanos
Last active December 16, 2015 08:48
Show Gist options
  • Select an option

  • Save thanos/5408040 to your computer and use it in GitHub Desktop.

Select an option

Save thanos/5408040 to your computer and use it in GitHub Desktop.
FInds AWS EC2 instances with a certain tag set.
def get_ec2_instances(**tags):
from pprint import pprint
from django.conf import settings
import boto
aws = boto.connect_ec2(settings.AWS_ACCESS_KEY_ID ,settings.AWS_SECRET_ACCESS_KEY)
reservations = aws.get_all_instances()
return [i for r in reservations = aws. for i in r.instances if set(tags.items()) & set(i.tags.item())]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment