无法调用start_query方法

时间:2019-03-28 13:04:07

标签: amazon-cloudwatchlogs amazon-cloudwatch-metrics amazon-cloudwatch aws-cloudwatch-log-insights

无法调用start_query方法

我正在尝试使用以下代码查询cloudwatch日志。但是我收到以下错误     TypeError: cloudwatchlogs.startQuery不是函数

似乎API无法找到startQuery方法。 请帮助我解决问题。

var AWS = require('aws-sdk');
var cloudwatchlogs = new AWS.CloudWatchLogs({apiVersion: '2014-03-28',
  region: 'us-west-2'
});
// Set the region 
exports.handler = (event,context,callback) => {
    console.log("hai");
    AWS.config.update({region: 'us-west-2'});
    var params = {
      endTime: 1553686248, /* required */
      logGroupName: '/aws/lambda/tset', /* required */
      queryString: 'fields  @message| filter @message like /START/| fields strcontains(@message, "$LATEST") as @CONTAINS_ap | stats sum(@CONTAINS_ap) as @sample',
      startTime: 1553538648,
      limit: 0
    };
      cloudwatchlogs.startQuery(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);           // successful response
    });
}

1 个答案:

答案 0 :(得分:2)

您使用的是哪个版本的“ aws-sdk”?在2.364.0中添加了StartQuery:https://github.com/aws/aws-sdk-js/blob/master/CHANGELOG.md#23640