I have this node.js function process() which is supposed to return a value when called. I am facing issue with creating a callback for my process(). The value should return from process() only after it gets response back from ec2.runInstances(params, function(err, data) call.
------------- Snippet from app.js (express.js)--------------------
var createEngine = require('./ec2_create.js');
app.get('/create', function (req, res) {
res.render('create', {
status: createEngine.process()
});
});
------------------------Code snippet from ec2_create.js -----------------------
function process(callback) {
var status = null;
// Create the instance
ec2.runInstances(params, function (err, data) {
if (err) {
//console.log("Could not create instance", err);
status = "Could not create instance: " + err;
} else {
var instanceId = data.Instances[0].InstanceId;
//console.log("Created instance", instanceId);
status = "Created instance: " + instanceId;
}
});
callback(status);
};
module.exports.process = process;