我有代码node.js,我尝试从AWS获取指标数据,但我有错误。 我在互联网上搜索但没有任何相同的问题。 这是我的源代码:
function getCloudwatchMetricData(queueName, callback) {
console.log("Get CloudWatch metric data of SQS: " + queueName);
var params = {
MetricDataQueries: [{
Id: queueName,
MetricStat: {
Metric: {
Dimensions: [{
Name: 'QueueName',
Value: queueName
}, ],
MetricName: 'ApproximateNumberOfMessagesVisible',
Namespace: 'AWS/SQS'
},
Period: 300,
Stat: 'Average',
Unit: 'Count'
},
ReturnData: true
}, ],
StartTime: startTime,
EndTime: endTime,
ScanBy: 'TimestampAscending'
};
cloudwatchClient.getMetricData(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
这是我的错误:
TypeError: cloudwatchClient.getMetricData is not a function
at getCloudwatchMetricData (/home/baonv/cowell-project/gitlab-cowell/servertechnology/uketoru/done/53434/local.js:194:22)
at Object.exports.handler (/home/baonv/cowell-project/gitlab-cowell/servertechnology/uketoru/done/53434/local.js:313:13)
at Object._executeSync (/usr/local/lib/node_modules/lambda-local/lib/lambdalocal.js:136:34)
at Object._execute [as execute] (/usr/local/lib/node_modules/lambda-local/lib/lambdalocal.js:39:22)
at /usr/local/lib/node_modules/lambda-local/bin/lambda-local:100:21
at Object.<anonymous> (/usr/local/lib/node_modules/lambda-local/bin/lambda-local:132:3)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
我尝试使用AWS CLI。它运行正常 这是CLI命令:
aws cloudwatch get-metric-data --metric-data-queries file://testdata/metric-data-queries.json --start-time 2018-05-20T00:00:00Z --end-time 2018-05-21T00:00:00Z --scan-by TimestampAscending
如果有任何想法或同样的问题,请帮助我。 这是指南: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#getMetricData-property
注意:我不想使用动作“getMetricStatistics” 感谢
答案 0 :(得分:0)
我首先要检查的是SDK版本参考。您可能正在参考最新的文档,但是您添加的脚本参考可能很旧。
请检查SDK参考的版本。
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.326.0.min.js"></script>