节点js aws lambda函数

时间:2018-12-02 07:13:00

标签: node.js 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处理程序代码后,它可以正常工作。

OutPUT

-------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

0 个答案:

没有答案