mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-11-30 19:34:32 -06:00
29 lines
1007 B
JavaScript
29 lines
1007 B
JavaScript
(function () {
|
|
function InstanceFetcher(properties) {
|
|
var self = this;
|
|
var AWS = require('aws-sdk');
|
|
var ec2 = new AWS.EC2({region: properties('region')});
|
|
var tagKey = properties('tagKey');
|
|
var tagValue = properties('tagValue');
|
|
|
|
this.onInstances = function (result) {
|
|
var allInstances = [];
|
|
result.Reservations.forEach(function (res) {
|
|
allInstances = allInstances.concat(res.Instances);
|
|
});
|
|
return allInstances.filter(function (reservation) {
|
|
if (reservation.State.Name !== "running") return false;
|
|
return reservation.Tags.some(function (t) {
|
|
return t.Key == tagKey && t.Value == tagValue;
|
|
});
|
|
});
|
|
};
|
|
|
|
this.getInstances = function () {
|
|
return ec2.describeInstances().promise().then(self.onInstances);
|
|
};
|
|
}
|
|
|
|
exports.InstanceFetcher = InstanceFetcher;
|
|
}).call(this);
|