AWS EC2 what is a reservation ID exactly and what does it represent?

I made a script that creates snapshots of our EC2 volumes. The script looks at which instances are running, which volumes are connected to those instances, and then creates snapshots for those volumes, ignoring the rest.

Using describe-instances, I get reservation IDs, not instance IDs. This is confusing, but it is as it is. When an instance is started, a reservation is created for that instance.

I'm still confused about the reservation concept.

Side note: I know what reserved instances are, which is different from what I'm describing here. A "reserved instance" means that you rent an instance for a year or two or three, and you get a price cut for that. So you reserve a t2.medium for one year, and if you don't use it, you still pay, but if you do use it, it's cheaper than normal.

Now back to the "reservation ID". The AWS FAQ says:

Every instance launched by EC2 has a reservation ID. A reservation ID has a one-to-one relationship with an instance launch request, but can be associated with more than one instance if you launch multiple instances using the same launch request.

Then there is this SE question: What is the purpose of 'Reservations' in Amazon EC2

It still is not clear what a reservation ID represents exactly

If you launch one instance at a time, each instance has its own unique reservation ID.

  • When or how can a single reservation ID be linked to multiple instances?
  • Can it be linked to several unrelated instances? Say I have a webserver and a database server. Can I start them under one reservation ID?
  • Or, can a reservation id only be linked to one instance that is started multiple times, like for load balancing purposes.

In our situation, all instances have a unique reservation ID, but I want to know in what situations this can change, for a script I'm running using describe-instances.


The ResearvationId has nothing to do with Reserved Instances. It is a unique value indicating a request to launch EC2 instances. A launch request may come from the cli, AutoScaling, or the AWS Management Console.

Each request to aws ec2 run-instances will return zero or more reservations of instances. Usually, it'll be one if it succeeds, but the docs say "zero or more" (1), so a single launch request may be broken-up into multiple reservations.

Usually, instances that are launched at one time get the same ReservationId, but that may not be a hard-and-fast rule. But launching 2 instances at 2 different times most likely will give different ReservationId values.

For example, as part of the aws ec2 run-instances command, you can indicate the minimum and maximum number of instances to launch simultaneously. Many times, this will be min = max = 1, but it can be more and/or different as long as 1 <= min <= max. You can also specify the number of instances to run when you launch new instances from the AWS Management Console. This can be seen on the "Step 3: Configure Instance Details" page.

When executing aws ec2 describe-instances, your results will be grouped by the ReservationId value based on how they were launched.

In generally, you don't need to be concerned about the ReservationId value unless you want to know if they were launched simultaneously at which point AmiLaunchIndex on the instance will differ from instance-to-instance within the reservation (0, 1, 2, etc.).

References:

  • (1) http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html

Consider reservation id as a Transactional ID. e.g If you buy a 5 tickets at one time. You have one Transaction ID but Five Booking ID.

In the same way, if you launch 1 instance at one time using aws ec2 run-instances, you will have one reservation ID and one Instance ID.

But if you launch 10 instance at one time using aws ec2 run-instances, you will have 1 reservation ID and 10 instance ID.