Created
June 25, 2019 14:14
-
-
Save loretoparisi/dcda5d843adb01193afe6da28b244d46 to your computer and use it in GitHub Desktop.
Get Docker Host IP Address for EC2 instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cp = require('child_process'); | |
const ec2 = function (callback) { | |
const URL = 'http://169.254.169.254/latest/meta-data/local-ipv4'; | |
// we make it silent and timeout to 1 sec | |
const args = [URL, '-s', '--max-time', '1']; | |
const opts = {}; | |
cp.execFile('curl', args, opts, (error, stdout) => { | |
if (error) return callback(new Error('ec2 ip error')); | |
else return callback(null, stdout); | |
}) | |
.on('error', (error) => callback(new Error('ec2 ip error'))); | |
}//ec2 |
Author
loretoparisi
commented
Jun 25, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment