【发布时间】:2021-10-15 06:55:27
【问题描述】:
我正在 Node.js 中创建一个 AWS Lambda 函数。我想使用 Cloudwatch GetMetricWidgetImage API 来获取仪表板快照,但似乎我遇到了麻烦。以下是我编写的代码,没有得到任何适当的响应。代码一直执行到 hello1 并且我得到的响应为空。
console.log('Loading function');
const aws = require('aws-sdk');
var cloudwatch = new aws.CloudWatch({apiVersion: '2010-08-01'});
console.log("hello");
exports.handler = async (event, context, callback) =>{
var widgetDefinition = {
MetricWidget: '[ "AWS/IVS", "ConcurrentViews" ]',
OutputFormat: 'image.png'
};
console.log("hello1");
cloudwatch.getMetricWidgetImage(widgetDefinition, function(err, data) {
if (err) {
console.log(err, err.stack) ; //error occured
//console.log("hello2");
}
else {
console.log(data.MetricWidgetImage); // successful
var response = {
statusCode: 200,
body: new Buffer(data.MetricWidgetImage).toString('base64')
};
console.log(response);
}
});
};
【问题讨论】:
标签: javascript amazon-web-services aws-lambda amazon-cloudwatch