All files / Service-Helper/lib/ec2 vm.js

41.67% Statements 5/12
0% Branches 0/2
0% Functions 0/7
41.67% Lines 5/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 361x                             1x           1x           1x           1x    
var AWS = require('aws-sdk');
/**
 *
 * @param {*} Conf - this should contain all the config and credential keys for cross account resource fetching
 * @param {*} accountStage - the stage in which we want to operate
 */
function EC2Service (Conf, accountStage) {
    // enable this in a better way to give the user option of specifying a credentials in case of assume roles/cross account creds/ etc...
    // this.credentials = new AWS.SharedIniFileCredentials({profile: Conf.creds.profile[accountStage || 'infra'], filename: `${Conf.creds.filelocation}`});
    // AWS.config.credentials = this.credentials;
    this.ec2Service = new AWS.EC2({
        region: process.env.AWS_REGION || 'eu-west-1'
    });
}
 
EC2Service.prototype.getVms = function (getStuff, callback) {
    this.ec2Service.describeInstances(getStuff,(e, d) => {
        return callback(e, d);
    });
}
 
EC2Service.prototype.stopVms = function (stopStuff, callback) {
    this.ec2Service.stopInstances(stopStuff, (e, d) => {
        return callback(e, d);
    });
}
 
EC2Service.prototype.startVms = function (startStuff, callback) {
    this.ec2Service.startInstances(startStuff, (e, d) => {
        return callback(e, d);
    });
}
 
module.exports = exports = EC2Service;