Skip to content

Instantly share code, notes, and snippets.

@splaice
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splaice/2c74c45f9c0b064d917a to your computer and use it in GitHub Desktop.
Save splaice/2c74c45f9c0b064d917a to your computer and use it in GitHub Desktop.
ec2 interface example
from ec2 import Instance, SecurityGroup, VPC
instances = Instance.objects.all()
web0 = Instance.objects.filter(name='web0')
# creating instances could be tricky, does creating or saving an instance run it?
i = Instance(**kwargs)
i.save()
i = Instance.objects.create(**kwargs)
i, _ = Instance.objects.get_or_create(**kwargs)
i.delete()
groups = SecurityGroup.objects.all()
webservers = SecurityGroup.objects.filter(name='web')
sg = SecurityGroup(name='web', description='web servers')
sg.save()
sg = SecurityGroup.objects.create(**kwargs)
sg, _ = SecurityGroup.objects.get_or_create(**kwargs)
sg.delete()
vpcs = VPC.objects.all()
vpc = VPC.objects.filter(cidr_block='10.10.0.0/16')
vpc = VPC(**kwargs)
vpc.save()
vpc = VPC.objects.create(**kwargs)
vpc, _ = VPC.objects.get_or_create(**kwargs)
vpc.delete()
# can do interesting things like
sg = SecurityGroup.objects.get(name='web')
i = Instance(security_group=sg, **kwargs)
# this could also be a lot of work if want to do this for all the parameters for instance creation
from ec2 import AvailabilityZone
az = AvailabilityZone.objects.get(name="us-west-1a")
i = Instance(availability_zone=az)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment