node.js - 节点js aws lambda函数
问题描述
谢谢您的意见。我以更简单的方式编写了相同的代码(我认为..)在下面的代码中,没有调用 ProcessRequest。
我不是开发人员,我正在尝试使用 lambda-nodejs 来完成我的活动。
这是代码:
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
function dispatch(intentRequest, callback) {
const sessionAttributes = intentRequest.sessionAttributes;
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.open('GET', "http://<server>:8086/query?db=rpt&q=select transactionName,responseTime from healthCheckTestV1 ORDER BY DESC LIMIT 9", true);
console.log("-------before SEND")
xhr.send();
console.log("AFTER SEND---------")
console.log("Inside Dispatch............")
xhr.onreadystatechange = processRequest;
function processRequest(e) {
console.log("processRequest function inside")
if (xhr.readyState == 4 && xhr.status == 200) {
var toDisplay = [];
var response = JSON.parse(xhr.responseText);
//console.log(xhr.responseText);
for (var i = 0; i < response.results.length; i++) {
for (var t = 0; t < response.results[i].series.length; t++) {
for (var j = 0; j < response.results[i].series[t].values.length; j++) {
var toSplit = response.results[i].series[t].values[j].toString() // VALUE
var splitted = toSplit.split(',');
//console.log(splitted[1]+"="+parseInt(splitted[2],10)+" seconds")
toDisplay.push(splitted[1] + "=" + parseInt(splitted[2], 10) + " seconds\n")
toDisplay.join()
//toDisplay.replace(/,/g," ")
}
console.log(toDisplay.toString().trim().replace(/,/g, " "))
}
}
}
}
callback(close(sessionAttributes, 'Fulfilled', {
'contentType': 'PlainText',
'content': `The status of your order is`
}));
}
// --------------- Main handler -----------------------
// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.
exports.handler = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
try {
dispatch(event,
(response) => {
callback(null, response);
});
} catch (err) {
callback(err);
}
};
但是当我在 Eclipse 中运行相同的代码时,在删除 lambda 处理程序代码后,它工作正常。
输出
-------before SEND
AFTER SEND---------
processRequest function inside
processRequest function inside
processRequest function inside
Security_Question=4 seconds
File_Download=31 seconds
View_File=11 seconds
Open_TEAM=32 seconds
File_Upload=50 seconds
Open_OneDrive=3 seconds
Logout=10 seconds
Login_OKTA=9 seconds
HomePage=5 seconds
解决方案
推荐阅读
- c# - 如何访问 httppostedfilebase 数组的单个元素?
- react-native - 如何将状态传递给父级?
- c - 使用 strtok 从文件中获取输入
- javascript - 在初始化之前获取不能得到东西
- powershell - 如何使用 PowerShell 将文本添加到 csv 文件中的现有文本
- javascript - 我怎样才能看到 Node.js 作为命令行参数传递的究竟是什么?
- r - 与 sf 结合的闪亮地图中的非反应性地图
- android - 用户第一次使用我的应用程序时如何设置 ACTION_OPEN_DOCUMENT_TREE 启动路径?
- c# - 在 Winforms 表单中嵌入 Powershell 窗口
- node.js - 为什么我在 Heroku 应用程序中收到 401 Unauthorized 错误?