We're using amazon EC2 and we want to keep track of instaces. Is the Amazon EC2 instance-id unique forever? i.e. If a VM has an instance id of i-12345678
is there a guarantee that when that instance terminates, that instance id won't ever be used again?
Asked
Active
Viewed 1.8k times
20

Yuri
- 220
- 1
- 6

Amandasaurus
- 31,471
- 65
- 192
- 253
-
I think @jedberg's answer is the right one. However, I would also point you to this article: https://web.archive.org/web/20160407141803/http://www.jackofallclouds.com/2009/09/anatomy-of-an-amazon-ec2-resource-id/ which has a very in-depth analysis (albeit with some guesswork) of how Amazon ID's are constructed. The guy who wrote it doesn't work for Amazon, but you can tell he did his homework :-). IMO it's worth the read just for informational purposes. – Matt Solnit Sep 29 '09 at 20:47
2 Answers
27
I asked Amazon, and this was their answer:
Instance ids are unique. You'll never receive a duplicate id. However, the current format of the instance id is an implementation detail that is subject to change. If you use the instance id as a string, you should be fine.
It's important to note that you will never receive the same ID twice. However, since you can't connect to other people's instances, this will probably be sufficient.
-
1And if you get a duplicate instance ID, it is a bug and you should report it to Amazon immediately. – jtimberman Sep 09 '09 at 07:21
-
I don't know what they're actually doing, but this would fit the current 32-bit version: http://preshing.com/20121224/how-to-generate-a-sequence-of-unique-random-integers/ (see section "A Non-Repeating Pseudo-Random Number Generator"). Then, when they get to the end, they can shift to something else (more bits, different digits (`[g-v]` instead of `[0-9a-f]`, for example), something). – lindes May 06 '15 at 23:53
-
1@lindes: I would guess 32 bit is a bit more of instances than ANY customer can launch in their life. You probably missed the second sentence of the amazon answer. They reuse instance ids immediately on other accounts. So if you have two accounts and use both you can actually get duplicates. – John Sep 25 '16 at 22:01
-
@john: Ahh. That seems _maybe_-implied in the quoted section from Amazon, and it is stated in the next paragraph from jedberg... Is that confirmed, though? I could easily read the from-Amazon text as implying globally-unique, as well; it's not explicit on that point. – lindes Sep 30 '16 at 17:37
-
Also, [longer instance IDs are coming](https://aws.amazon.com/blogs/aws/heads-up-longer-ec2-ebs-resource-ids-coming-in-2016/). Looks like they're going to 68 bits, maybe? Or 64 bits with an option for growth via an initial 4-bit flag set or version number or something. I also wonder if they'll switch to base64 or similar encoding at some point, instead of the current base16. – lindes Sep 30 '16 at 17:39
-
@lindes: I just wanted to mention the longer 17 char IDs. I think they "intended" to re-use them that's why they did not guarantee unique IDs over multiple accounts. However that probably causes hell of a mess within their own databases so we are getting longer IDs now with enough space. Amazon/AWS will almost certainly be a platform of computer history before a 64bit or larger number runs out of space. – John Sep 30 '16 at 20:31
-
1@lindes: The ID is definitely not globally unique. Amazon has told me they are not globally unique and I've personally seen duplicates in different accounts. The new IDs may be globally unique for now, but I wouldn't depend on that to always be the case. – jedberg Oct 01 '16 at 21:28
-
@John I wondered if that was sarcasm precisely because 32 bit seemed like more than enough for every computer on the internet at one time too. And I think we've learned to be careful thinking this way. Imagine the customer is global company with 5 major regions, and 10 business areas per team. Each needs a cluster of 1024 cheap machines to batch process their hourly reports. Using spot instances set to scale and basically hourly they're replacing all instances by the tight config settings. They get 10 years before AWS has to make the IDs longer. Not counting backfill, and other uses for EC2. – dlamblin Feb 12 '20 at 21:05
-1
I couldn't find anything online, but I wouldn't count on guaranteed uniqueness, even if the current format would accommodate >4 billion IDs.

user5336
- 2,379
- 1
- 15
- 9