When trying to do a HTTP request in a lambda function, the following GET does not seem to be executed:
var request = require("request");
var myMonzoBalance;
request({
uri: "https://api.monzo.com/balance?account_id=acc_XXXXXXXXX",
method: "GET",
headers: {'Authorization': 'Bearer XXXXXXX'}
}, function(error, response, body) {
myMonzoBalance = JSON.parse(body).balance;
console.log(myMonzoBalance);
});
console.log(myMonzoBalance);
The value for myMonzoBalance will be undefined once the code is executed.
Actually if I try to give myMonzoBalance a value inside the request function, it will not make any difference - undefined.
The above code works fine when run in Terminal. Also I have node_modules within the library of that same lambda function.
Any ideas about why this could be happening?
Many thanks!