【发布时间】:2019-02-26 10:29:28
【问题描述】:
我有以下代码sn-p
const AWS = require('aws-sdk');
exports.handler = async (event, context) => {
// Set the region
console.log('line1');
AWS.config.update({region: 'cn-north-1'});
console.log('line2');
// Create CloudWatch service object
var cw = new AWS.CloudWatch({apiVersion: '2010-08-01'});
console.log('line3');
//Create parameters JSON for putMetricData
var params = {
MetricData: [
{
MetricName: 'PAGES_VISITED',
Dimensions: [
{
Name: 'UNIQUE_PAGES',
Value: 'URLS'
},
],
Unit: 'None',
Value: 1.0
},
],
Namespace: 'SITE/TRAFFIC'
};
console.log('line4');
if (cw){
console.log('cw is not null');
}else{
console.log('cw is null');
}
cw.putMetricData(params, function(err, data) {
console.log('callback function');
if (err) {
console.log("Error", err);
} else {
console.log("Success", JSON.stringify(data));
}
});
console.log('line5');
return "the result";
};
在我在 Lambda 控制台中对其进行测试之后。我可以看到正在创建的那些 Cloudwatch 日志。但是我看不到正在创建 Cloudwatch 指标。
我已将 Lambda 的角色设置为具有 Cloudwatch:PutMetricData 策略
【问题讨论】:
标签: node.js amazon-web-services aws-lambda metrics