Standardize custom metrics with Powertools

Standardize custom metrics with Powertools

Metrics creates custom metrics asynchronously by logging metrics to standard output following Amazon CloudWatch Embedded Metric Format (EMF).

Select language:

Using Powertools Metrics with TypeScript:

Install the library in your project:

npm install @aws-lambda-powertools/metrics
                                                      


The Metrics utility must always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition, Metrics can track cold start and emit the appropriate metrics.

import { Metrics } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export const handler = async (_event, _context): Promise<void> => {
    // ...
};
                                                      



Created by:

David Boyne

David Boyne

Helping people learn about event-driven architectures and serverless

Follow on LinkedIn

James Eastham

James Eastham

I am a Cloud Infrastructure Architect with AWS Professional Services.

Rahul Popat

Rahul Popat

Senior Specialist Solutions Architect at AWS

Follow on LinkedIn