npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@thedesignium/cdk-log-notifier

v2.0.2

Published

The AWS CDK Construct to build a system that gather CloudWatch logs, filter and post to Slack.

Downloads

688

Readme

cdk-log-notifier: Filter CloudWatch logs and post to Slack.

The AWS CDK Construct to build a system that gather CloudWatch logs, filter and post to Slack.

screenshot

Example Usage

Watch the all logs contains "ERROR" from Lambda functions.

const logNotifier = new LogNotifier(this, 'logNotifier', {
  filterPattern: logs.FilterPattern.allTerms('ERROR'),
  slackIncomingWebhookUrl: 'https://hooks.slack.com/...', // Use yours.
});

logNotifier.watch(lambdaFunc1.logGroup);
logNotifier.watch(lambdaFunc2.logGroup);

Installation

npm i @thedesignium/cdk-log-notifier

API Reference

Class: LogNotifier

new LogNotifier(scope: cdk.Construct, id: string, props: LogNotifierProps)

The properties in props:

  • filterPattern: The FilterPattern object in aws-cloudwatch module. The logs is filtered as specified here. Required.

  • slackIncomingWebhookUrl: The Incoming Webhook URL of Slack. Create for the Slack channel the logs should be posted. Required.

  • dateTimeFormatOptions: The arguments of the DateTimeFormat constructor, used to format the datetime which shown at the bottom of the Slack message. If omitted, it's formatted like 12/20, 3:00:00 AM UTC. Optional.

    Example:

      dateTimeFormatOptions: {
        locales: 'ja-JP',
        timeZone: 'Asia/Tokyo',
        month: 'numeric',
        day: 'numeric',
        hour: 'numeric',
        minute: 'numeric',
        second: 'numeric',
      }

Static Method: fromAttributes

LogNotifier.fromAttributes(scope: cdk.Construct, id: string, attrs: LogNotifierAttributes): LogNotifier

Instantiate from the attributes. Put the value of logNotifier.attributes as attrs parameter.

Method: watch

logNotifier.watch(logGroup: logs.LogGroup): void

Add the log group to watch list to notify. The logs in the watched log groups are filtered by the filterPattern and posted to Slack.

Property: attributes

attributes: LogNotifierAttributes

To use with LogNotifier.fromAttributes().

Containing Resources

Limitation

The watch() method attaches a Subscription to the subject logGroup. The number of subscription can be attached to a logGroup, however, is only one. So it'll fail if the logGroup has another subscription already. Similary, the watched logGroup can't be attached another subscription nor watched from another LogNotifier.

Motivation

There were 2 requirements:

  1. Notice the all logs produced by console.error()(not only the crash report such InvocationError)
  2. Jump easily to CloudWatch via link

We tried Lambda's error metric + CloudWatch Alarm + Chatbot and CloudWatch Metrics Filter + CloudWatch Alarm + Chatbot, but the former system don't satisfy [1] and the latter system don't satisfy [2]. That's why we need this.

FAQ

Cross Stack?

Possible. Export all values in LogNotifier.prototype.attributes, import it and use LogNotifier.fromAttributes() in another Stack.

How can I customize the Slack bot icon or name?

You can set at Slack App setting page, or Incoming Webhook configuration page if you use Legacy Incoming Webhook.

No support for other languages than TypeScript?

I'm not familiar with jsii so I leave it for now. Contribution is welcome.