eslint-plugin-stedi-aws-rules
eslint-plugin-stedi-aws-rules copied to clipboard
Do not report CloudWatch custom metrics using SDK calls, use Embedded Format instead
Rule name
no-cloudwatch-direct-reporting
Use case description
Reporting metrics using Cloudwatch SDK calls creates unnecessary overhead and makes your Lambdas slower. You should use Embedded Metric Format to log any custom metrics inside Lambdas.
Examples
Incorrect
var cloudwatch = new AWS.CloudWatch();
cloudwatch.getMetricWidgetImage(params, function (err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
Correct
const { metricScope } = require("aws-embedded-metrics");
const myFunc = metricScope(metrics =>
async () => {
// ...
});
exports.handler = myFunc();
References: