eventbridge-email-notifier
v0.2.1
Published
EventBridge rule target that sends email through Amazon SNS with a custom subject.
Maintainers
Readme
EventBridge Email Notifier (CDK v2)
EventBridge rule target that sends email through Amazon SNS with a custom subject.
Features
- Plug into an existing EventBridge rule via
rule.addTarget(...) - Custom SNS email subject (EventBridge cannot set subject when SNS is a direct target)
- Subject sanitization for SNS Publish limits (control characters removed, max 99 chars)
- EventBridge target dead-letter queue and retry settings
How it works
EventBridge invokes a small Lambda publisher. The Lambda calls SNS Publish with your subject and message. On the same rule, targets that share a topic and subject reuse one publisher Lambda; different subjects or topics get separate functions. Email subscriptions are not created by this library, and the topic resource policy is not modified—add subscriptions in the console or API when addresses change.
Installation
npm
npm install eventbridge-email-notifieryarn
yarn add eventbridge-email-notifierpnpm
pnpm add eventbridge-email-notifierUsage
import { Duration } from 'aws-cdk-lib';
import * as events from 'aws-cdk-lib/aws-events';
import * as sns from 'aws-cdk-lib/aws-sns';
import * as sqs from 'aws-cdk-lib/aws-sqs';
import { EventBridgeEmailNotifier } from 'eventbridge-email-notifier';
const topic = new sns.Topic(this, 'AlertTopic');
const rule = new events.Rule(this, 'PipelineRule', {
eventPattern: {
source: ['aws.codepipeline'],
},
});
rule.addTarget(new EventBridgeEmailNotifier(topic, {
subject: 'Pipeline failed',
message: events.RuleTargetInput.fromText('Check CodePipeline'),
deadLetterQueue: new sqs.Queue(this, 'NotifierDlq'),
retryAttempts: 2,
maxEventAge: Duration.hours(2),
}));Options
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| subject | string | (required) | SNS email subject (sanitized to SNS limits) |
| message | events.RuleTargetInput | entire EventBridge event | Payload published as the SNS message body |
| deadLetterQueue | sqs.IQueue | none | EventBridge target DLQ |
| retryAttempts | number | 185 | EventBridge retry attempts |
| maxEventAge | Duration | 24 hours | Maximum event age for retries |
API
See API.md.
Requirements
- Node.js
>= 20.0.0 aws-cdk-lib^2.272.0constructs^10.5.1
License
This project is licensed under the (Apache-2.0) License.
