pambda-cwlogs

0.1.0 • Public • Published

pambda-cwlogs

Pambda to output logs to CloudWatch Logs.

Installation

npm i pambda-cwlogs -S

Usage

import { compose, createLambda } from 'pambda';
import { cwlogs } from 'pambda-cwlogs';

export const handler = createLambda(
  compose(
    cwlogs({
      logGroupName: 'Sandbox',
      makeLogStreamName(event, context) {
        return event.userId;
      },
    }),

    // Subsequent pambdas can log messages.
    next => (event, context, callback) => {
      context.logEvent('Path: %s', event.path);
    }
  )
);

cwlogs(options)

Generate and return a pambda which adds the logger function to context.

  • options.logGroupName
    • The name of the log group.
  • options.makeLogStreamName(event, context)
    • The function makes the name of the log stream.
    • If this function returns falsy, logs are discarded.

context.logEvent(...args)

A function that is added by this pambda to context.

It outputs the message specified by argument args to CloudWatch Logs.

License

MIT

Package Sidebar

Install

npm i pambda-cwlogs

Weekly Downloads

3

Version

0.1.0

License

MIT

Unpacked Size

7.05 kB

Total Files

4

Last publish

Collaborators

  • nak2k