Quantcast
Channel: Billy Cravens » cfml - Billy Cravens - Geeky Little Programmer Dude in Houston
Viewing all articles
Browse latest Browse all 4

How to determine if you’re on Amazon

$
0
0

Quick little snippet on determining if your ColdFusion app is running on an Amazon Web Services instance (only tested in Railo)


 function isAWS () {
hostname = createObject("java", "java.net.InetAddress").localhost.getHostName();
 parseHost = listToArray(hostname,'-');
return (arrayLen(parseHost)==2 && trim(parseHost[1])=='ip' && len(parseHost[2]==8);
}

 

Basically it grabs the host name (in Java) and checks to see that it matches the AWS convention (ip-01234567). Obviously not foolproof, as you could use that same naming convention, or AWS could change it.

Keep in mind that this isn’t as fast as checking against Amazon’s internal metadata REST API (for example, to get hostname, do an HTTP GET to http://169.254.169.254/latest/meta-data/hostname and parse against format: ip-1-2-3-4.ec2.internal where 1-2-3-4 would represent the internal IP address) when you’re inside EC2, but would fail outside of EC2 (and a try-catch would be much slower)


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images