Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What is the most reliable and simple way to detect, from within the host, that it's running in EC2 ?

The goal is to apply some changes on boot and move some of the things in the /mnt partition (because of disk space). Because it happens directly after the OS image has been instantiated there isn't a lot of software installed (eg: curl is missing on the Ubuntu AMIs).

share|improve this question
    
Why would you not know you are running on EC2 in the first place? –  EEAA Jul 25 '13 at 21:48
    
rDNS the IP address... –  Nathan C Jul 25 '13 at 21:48
    
@NathanC - that doesn't work in a VPCed instance. –  EEAA Jul 25 '13 at 21:49
    
@EEAA True, but that wasn't mentioned. –  Nathan C Jul 25 '13 at 22:23
    
Thanks guys. @EEAA: If you ship an install script you don't know where it's going to execute. It's not an end-goal but detecting EC2 is still useful in some cases. –  zimbatm Jul 26 '13 at 17:37
add comment

1 Answer

After looking into chef's ohai code, I can see that they use two checks: the existence of a http server on 169.254.169.254 and the existence of fe:ff:ff:ff:ff:ff in the arp table.

This can be simulated like that:

arp | grep fe:ff:ff:ff:ff:ff && wget -t 1 -T 2 -S --spider http://169.254.169.254/1.0/
share|improve this answer
1  
It should be noted that 169.254.169.254 is also available in EC2-alike infrastructures like Eucalyptus, not just EC2 proper. –  ceejayoz Jul 25 '13 at 22:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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