TheDesignium.CDKLogNotifier
2.0.2
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
<PackageReference Include="TheDesignium.CDKLogNotifier" Version="2.0.2" />
paket add TheDesignium.CDKLogNotifier --version 2.0.2
#r "nuget: TheDesignium.CDKLogNotifier, 2.0.2"
// 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.
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 like12/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:
- Notice the all logs produced by
console.error()
(not only the crash report such InvocationError) - 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 | Versions 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. |
-
.NETCoreApp 3.1
- Amazon.CDK.Lib (>= 2.51.0 && < 3.0.0)
- Amazon.JSII.Runtime (>= 1.81.0 && < 2.0.0)
- Constructs (>= 10.0.5 && < 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.