TheDesignium.CDKLogNotifier 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TheDesignium.CDKLogNotifier --version 2.0.2                
NuGet\Install-Package TheDesignium.CDKLogNotifier -Version 2.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TheDesignium.CDKLogNotifier" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TheDesignium.CDKLogNotifier --version 2.0.2                
#r "nuget: TheDesignium.CDKLogNotifier, 2.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TheDesignium.CDKLogNotifier as a Cake Addin
#addin nuget:?package=TheDesignium.CDKLogNotifier&version=2.0.2

// Install TheDesignium.CDKLogNotifier as a Cake Tool
#tool nuget:?package=TheDesignium.CDKLogNotifier&version=2.0.2                

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.
  • dateTimeFormat: The DateTimeFormat object 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.
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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 98 10/8/2024
2.0.4 66 7/31/2024
2.0.2 157 5/15/2023