本文介绍了Amazon Connet的getCurrentMetricData不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我正在与Amazon Lambda合作进行一个项目。

Recently I am working on a project with Amazon Lambda.

我创建了一个lambda函数,如下所示

I created a lambda function as following

var AWS = require ('aws-sdk');
exports.handler = (event, context, callback) => {
    // TODO implement
    var connect = new AWS.Connect({apiVersion: '2017-08-08'});
    var params = {
        InstanceId: '' /* required */
    };
    connect.getCurrentMetricData(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else   {
            const response = {
                statusCode: 200,
                body: JSON.stringify(data)
            };
            callback(null, data);
      }           // successful response
    });

    // const response = {
    //         statusCode: 200,
    //         body: JSON.stringify(typeof connect.getCurrentMetricData)
    // };
    // callback(null, response);
};

但是日志显示connect.getCurrentMetricData不是函数。

But the log said connect.getCurrentMetricData is not a function.

有人可以帮助我解决此错误吗?非常感谢。

Anyone can help me with this error ? Thanks a lot.

ps,我在Amazon Lambda在线编辑器(nodejs 8.10)中编写了代码,并测试了其他connect函数(例如createUser,deleteUser),typeof结果为function 。

ps, I wrote the code in Amazon Lambda online editor (nodejs 8.10) and I tested other connect's functions like createUser, deleteUser, the typeof result is function. Only when it comes to getCurrentMetricData, the typeof result will be undefined.

谢谢

推荐答案

var AWS = require ('aws-sdk');
AWS.config.region = 'your Region';
var connect = new AWS.Connect(); 

exports.handler = (event, context, callback) => {
var AGENTS_ON_CALL_VALUE;
var dataContent = {
  CurrentMetrics: [  
    { Name: 'AGENTS_ON_CALL',
      Unit: 'COUNT'
    },
  ],
  Filters: { 
    Channels: [ 'VOICE' ],
    Queues: [ 'Your Queue ID']
  },
  InstanceId: 'Connect InstanceID',
  Groupings: [ 'QUEUE' ],
  MaxResults: 1
};

connect.getCurrentMetricData(dataContent, function(err, data) {
    var jsonstring = JSON.stringify(data);
    if (err){
        console.log(err, err.stack);
    } else{    
        var obj = JSON.parse(jsonstring);
        AGENTS_ON_CALL_VALUE = obj.MetricResults[0].Collections[0].Value;
        console.log(AGENTS_ON_CALL_VALUE);    
        callback(null,"Finish getting Data"); 
    }  
});
}

问题已解决。获取最新的AWS-SDK。否则,它将返回getCurrentMetricData不是函数错误。

Problem Solved. Get the Newest AWS-SDK. Otherwise, it will return getCurrentMetricData is not a function error.

这篇关于Amazon Connet的getCurrentMetricData不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 13:34