closest-ec2-region

node-whichregion ================

  • libgeoip
brew install libgeoip
closestEC2Region = require("closest-ec2-region")();
 
var ip = "xxx.xxx.xx.xx";
 
closestEC2Region(ip, function(errregionName) {
    
});
 
var express = require("express"),
closestEC2Region = require("closest-ec2-region")();
 
var server = express();
 
server.get("/ec2/region", function(reqres) {
  closestEC2Region(req, function(errregion) {
    res.end(region);
  });
});
 
closestEC2Region = require("closest-ec2-region")({
  cityDataPath: "/path/to/city/data"
});
 
var ip = "xxx.xxx.xx.xx";
 
closestEC2Region(ip, function(errregionName) {
    
});

With node-ectwo

 
closestEC2Region(ip, function(errregionName) {
  ectwo.regions.findOne({ name: regionName || "us-east-1" }, function(errregion) {
    //do stuff with the target region 
  });
});