eslint-plugin-stedi-aws-rules icon indicating copy to clipboard operation
eslint-plugin-stedi-aws-rules copied to clipboard

Do not report CloudWatch custom metrics using SDK calls, use Embedded Format instead

Open RafalWilinski opened this issue 5 years ago • 0 comments

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:

RafalWilinski avatar Oct 02 '20 08:10 RafalWilinski