UNPKG

dynupdate-aws

Version:

NodeJS module to update no-ip and submit your AWS instance IP as a dynamic dns update request

6 lines 1.76 kB
/** * @license dynupdate-aws - v0.0.1 * (c) 2013 Julien VALERY https://github.com/darul75/dynupdate-aws * License: MIT **/ function DynUpdateAws(){this.options={},this.init(),this.ec2=new AWS.EC2(this.options),this.dynupdate=dynupdate,this.daemon(this.options,function(a,b){a?console.log(a):console.log(b)})}var AWS=require("aws-sdk"),dynupdate=require("dynupdate");DynUpdateAws.prototype.init=function(){var a=process.argv.splice(2);return a.length<6?(process.argv=process.argv.concat(a),void 0):(a.forEach(function(a,b){console.log(b+": "+a)}),this.options.accessKeyId=a[0],this.options.secretAccessKey=a[1],this.options.region=a[2],this.options.instanceId=a[3],this.options.auth=a[4],this.options.hostname=a[5],process.argv=process.argv.concat(a),this)},DynUpdateAws.prototype.daemon=function(a,b){if(!(a.accessKeyId&&a.secretAccessKey&&a.region&&a.instanceId&&a.auth&&a.hostname))return b(new Error("missing parameters: <AWS-accessKeyId> <AWS-secretAccessKey> <AWS-region> <AWS-instanceId> <NO-IP-auth> <NO-IP-hostname>"));var c=this,d=setInterval(function(){console.log("----- getting aws info "),c.ec2.describeInstances({},function(c,e){if(c)return console.log(c),clearInterval(d),b(c);var f=e.Reservations;f.forEach(function(c){var e=c;e.Instances.forEach(function(c){var e=c.InstanceId;console.log("current instance id "+e),e===a.instanceId&&c.PublicIpAddress&&(console.log("IP is "+c.PublicIpAddress),console.log('----- sending update to no-ip for domain "'+a.hostname+'"'),a.myip=c.PublicIpAddress,dynupdate.dynupdate(a,function(a,c){return a?(console.log(a),void 0):(console.log("----- job is done"),console.log("status "+c),clearInterval(d),b(null,"ok"))}))})})})},5e3);return this};var dynupdateAws=new DynUpdateAws;module.exports=dynupdateAws;