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?

up vote 25 down vote accepted

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 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.

  • 1
    the website is down. It would be favorable if you post the essence of the website also in your response, that would make your answer valid and useful even after a link goes down. I've seen it happening many times. – John Sep 25 '16 at 22:03
  • 1
    @John as a general rule, I agree with you, but in this case the article is all about the details; there's no "boiled down essence" that would be worth posting. I changed my answer to use a Wayback Machine link. – Matt Solnit Oct 19 '16 at 3:32
  • @MattSolnit This would have been better as a comment then. If you can't summarise in an answer (which seems fair enough in this case), then it isn't really a Stack Overflow answer. – Duncan Jones Feb 23 at 10:03

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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