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?

  • I think @jedberg's answer is the right one. However, I would also point you to this article: web.archive.org/web/20160407141803/http://… 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

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.

  • 1
    And if you get a duplicate instance ID, it is a bug and you should report it to Amazon immediately. – jtimberman Sep 9 '09 at 7:21
  • I don't know what they're actually doing, but this would fit the current 32-bit version: preshing.com/20121224/… (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 6 '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
  • 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 1 '16 at 21:28

I couldn't find anything online, but I wouldn't count on guaranteed uniqueness, even if the current format would accommodate >4 billion IDs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.