-
Notifications
You must be signed in to change notification settings - Fork 35
/
IMDSSample.js
41 lines (36 loc) · 974 Bytes
/
IMDSSample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// NodeJS Sample for IMDS
var http = require('http');
function JsonQueryIMDS(path, callback)
{
api_version = '2021-02-01';
imds_server = '169.254.169.254';
result = ''
// Set your node js environment variable in .env to bypass proxies.
// Aka NO_PROXY = "*"
http.get({
host: imds_server,
path: '/metadata' + path + '?api-version=' + api_version,
headers: {'Metadata': 'True'}
}, function(response) {
var statusCode = response.statusCode;
if (statusCode != 200)
{
console.log('Request failed: ')
}
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
result = body;
callback(result);
});
})
}
// query /instance metadata
JsonQueryIMDS('/instance', function(result) {
// display raw json
console.log(result);
// parse json
// ..
});