问题
Recently I am working on a project with Amazon 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);
};
But the log said connect.getCurrentMetricData is not a function.
Anyone can help me with this error ? Thanks a lot.
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.
Thanks
回答1:
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");
}
});
}
Problem Solved. Get the Newest AWS-SDK. Otherwise, it will return getCurrentMetricData is not a function error.
来源:https://stackoverflow.com/questions/52567394/amazon-connets-getcurrentmetricdata-is-not-a-function