Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I'm just starting to explore amazon ec2. And I want to hear some explanations or may be some brief examples of how and why do you need 'reservations' in amazon ec2. I'm using python framework boto to manage Amazon Service. And so far I don't really see any reasons why do we have this extra step in order to get your instances, for example:

reservations = ec2.get_all_instances()

instances = [instance for res in reservations for instance in res.instances]

That's how I get all my instances, some times I do it like this:

reservation = ec2.run_instances(image_id, min_count, max_count, key_name .....)

instance = reservation.instances[0]

And then I use those instances to attach volumes, add tags, add security groups and so on... But what is the purpose of boto.ec2.instance. Reservation (I'm not asking only about boto framework, of course, it's preferred, but in a whole meaning of this in Amazon EC2)

>>> reservation = reservations[0]

>>> reservation


>>> dir(reservation)

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'connection', 'endElement', 'groups', 'id', 'instances', 'item', 'owner_id', 'region', 'startElement', 'stop_all']

>>> reservation.__class__

<class 'boto.ec2.instance.Reservation'>

I couldn't find any useful methods. Please explain me why do we need this? What's the reason it to be there? In what cases you would use it?

1 Answer

0 votes
by (44.4k points)

A reservation is an act of launching instances. Basically, a reservation is what you are doing, whereas an instance is what you get. If you launch multiple instances from one image via run_instances() you create one reservation, however, get multiple instances.

run_instances along with Reservation.stop_all() permits you to run a bunch of instances, wait for them to finish the task and then stop them all at once.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories