aws-lambda-powertools-correlation
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

aws-lambda-powertools-correlation

Correlation Ids for aws-lambda-powertools

Features

  1. Middleware to enable injecting correlation ids from the request into the AsyncLocalStorage
import { enableCorrelationIds } from '@aws-lambda-powertools-correlation';
import middy from '@middy/core';
import * as Lambda from 'aws-lambda';

export const handler = (_handler: Lambda.APIGatewayProxyHandlerV2) => {
  return middy(_handler).use(enableCorrelationIds());
};
  1. Utility to extend the powertools logger with correlation ids: injectCorrelationIds(logger)
import { injectCorrelationIds } from '@aws-lambda-powertools-correlation';
import { Logger } from '@aws-lambda-powertools/logger'

const logger = new Logger();

export const handler = (_handler: Lambda.APIGatewayProxyHandlerV2) => {
  return middy(_handler)
      .use(enableCorrelationIds())
      .before(() => { injectCorrelationIds(logger) });
};
  1. Utility to get correlation ids from the AsyncLocalStorage: getCorrelationIds()
import { useCorrelationIds } from '@aws-lambda-powertools-correlation';

const correlationIds = useCorrelationIds();

Dependencies

  • @aws-sdk/util-dynamodb
  • @aws-lambda-powertools/logger

Package Sidebar

Install

npm i aws-lambda-powertools-correlation

Weekly Downloads

80

Version

0.1.1

License

GNU

Unpacked Size

55.6 kB

Total Files

11

Last publish

Collaborators

  • idanielbot