Created
September 25, 2012 23:39
-
-
Save garnaat/3785118 to your computer and use it in GitHub Desktop.
Most concise way to extract list of Instances from a list of Reservations in boto
This file contains hidden or 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
# | |
# EC2 returns a list of Reservation objects when you call DescribeInstances. | |
# Usually, you just want the Instance objects that are embedded in the | |
# Reservation object. This shows how to use the magic of nested list | |
# comprehensions to construct a one-liner to get the Instance objects. | |
>>> import boto | |
>>> ec2 = boto.connect_ec2() | |
>>> reservations = ec2.get_all_instances() | |
>>> instances = [i for r in reservations for i in r.instances] | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment