Node.js Lambda Function is invalid "Amazon Alexa
UPDATE: I had an error in my http request endpoint. I have not set the appropriate authentication options to capture a lot of errors, perhaps this one specific.
My question is similar to the one here:
However, solving this question does not solve my problem. So I am making an HTTP request to the xsjs service in the Hana cloud. I am getting a "response not valid" error. I do not understand why. Here is my function:
// Create a web request and handle the response.
function httpGet(query, callback) {
console.log("/n QUERY: "+ query);
var host = 'datacloudyd070518trial.hanatrial.ondemand.com';
var path = '/LocationInformation/getLocationInfo.xsjs?location=';
var hostname = 'https://' + host + path + query;
var auth = 'user1:D1anafer';
var req = http.request({'hostname': hostname,
'auth': auth
}, (res) => {
var body = '';
res.on('data', (d) => {
body += JSON.stringify(d);
});
res.on('end', function () {
callback(body);
});
});
req.end();
req.on('error', (e) => {
console.error(e);
});
}
And the function that calls it:
'getNewsIntent': function () {
//self = this;
httpGet(location, function (response) {
// Parse the response into a JSON object ready to be formatted.
//var output = JSON.parse(response);
//output = output['change'];
var output = response;
var cardTitle = location;
var cardContent = output;
alexa.emit(':tellWithCard', output, cardTitle, cardContent);
});
},
Thanks -Diana
source to share
Inside your AWS account, go to your function Lambda
and click the tab monitoring
where you will see "View Logs in Cloudwatch" in the right corner. If you click this link and you will see errors that are being produced.
You can also use console.log()
to log any information returned from your REST api that will log in the cloud and can help you see where your errors are.
source to share
It's just a guess from my head. It will take some detailed error message as described above to really help.
But just a guess: your http.request () is using http module
( https://nodejs.org/api/http.html ) and you are accessing the https resource. If so, there is a module https ( https://nodejs.org/api/https.html ) or use something like axios https://www.npmjs.com/package/axios or requestjs ( https: // github .com / request / request ), this will handle both.
As I said, just blind guessing with no detailed error message and no review of your claims statements, but I'm happy to dive deeper if you have the details.
NTN
source to share
Your callback from Lambda should return a valid status code and body. Like this:
let payload = {
statusCode: 400,
body: JSON.stringify('body'),
headers: {"Access-Control-Allow-Origin": "*"}
};
callback(null, payload);
Also, to call this from client side code, you need to pass in the CORS header.
source to share