AWS-SDK Cloudwatch GetMetricData API函数不返回数据

时间:2019-06-04 14:05:10

标签: aws-sdk aws-sdk-nodejs

我想设置一个Lambda,使用Node.js查询Cloudwatch并获取Lambda使用的平均调用次数,目标是当我们接近达到调用限制时,我们将触发通知当我们达到极限时提醒我们。

我能够查询CW数据,但是当我运行脚本时,在一段时间内没有返回任何数据。我不确定自己的脚本在做什么错。

Don't ask again

当代码运行时,它不返回任何数据,我所看到的是下面看到的输出。我尝试使用不同的Lambda函数,但得到的结果相同。我不确定API调用返回的数据出了什么问题。

const AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
const cloudwatch = new AWS.CloudWatch();
const webhook = require('send-webhook');
const SSO_URL = "URL1";
const URLS = ['webhook'];

//var endTime = time.Now();
//var duration = time.ParseDuration("-5m");
//var startTime = endTime.Add(duration);

var params = {
  EndTime: '2019-06-04T08:45:00Z',
  MetricDataQueries: [
    {
      Id: 'concurrencycount',
      Label: 'Average concurrency',
      MetricStat: {
        Metric: {
          Dimensions: [
            {
              Name: 'FunctionName',
              Value: 'LambdaName'
            },
          ],
          MetricName: 'Invocations',
          Namespace: 'AWS/Lambda'
        },
        Period: '300',
        Stat: 'Average',
        Unit: 'Count'
      },
      ReturnData: false
    },
  ],
  StartTime: '2019-06-04T08:00:00Z',
  //ScanBy: TimestampDescending
};

//exports.handler = function(event, context){
cloudwatch.getMetricData(params, function(err, data) {
  if (err) console.log(err, err.stack);
  else console.log(data)
})
//}

1 个答案:

答案 0 :(得分:0)

我相信ERROR in [at-loader] ./ClientApp/components/app/fetchdata/search.ts:4:23 TS7016: Could not find a declaration file for module 'typeahead.js'. 'D:/Projects/Vue2/node_modules/typeahead.js/dist/typeahead.bundle.js' implicitly has an 'any' type. Try `npm install @types/typeahead.js` if it exists or add a new declaration (.d.ts) file containing `declare module 'typeahead.js';` 告诉Cloudwatch仅返回统计信息,而不返回指标本身。