Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ses identity notification #1118

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/aws-email/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ export default $config({
};
},
async run() {
const topic = new sst.aws.SnsTopic("MyTopic");

const email = new sst.aws.Email("MyEmail", {
sender: "[email protected]",
publishers: {
Bounce: topic,
},
});

const api = new sst.aws.Function("MyApi", {
Expand Down
45 changes: 45 additions & 0 deletions platform/src/components/aws/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Component, Transform, transform } from "../component";
import { Link } from "../link";
import { Input } from "../input";
import { Dns } from "../dns";
import { SnsTopic } from "./sns-topic";
import { dns as awsDns } from "./dns.js";
import { ses, sesv2 } from "@pulumi/aws";
import { permission } from "./permission";
Expand Down Expand Up @@ -105,6 +106,27 @@ export interface EmailArgs {
* ```
*/
dmarc?: Input<string>;

/**
* The SNS topics to publish bounce, complaint, and delivery notifications to. To see how to properly proccess bounces and complaints please read [Setting up event notifications for Amazon SES]{@link https://docs.aws.amazon.com/ses/latest/dg/monitor-sending-activity-using-notifications.html}
*
* @example
*
* ```js
* {
* publishers: {
* Bounce: topic,
* Complaint: topic,
* Delivery: topic,
* }
* }
* ```
*/

publishers?: Partial<
Record<"Bounce" | "Complaint" | "Delivery", Input<SnsTopic>>
>;

/**
* [Transform](/docs/components#transform) how this component creates its underlying
* resources.
Expand Down Expand Up @@ -227,6 +249,8 @@ export class Email extends Component implements Link.Linkable {
waitForVerification();
});

createIdentityPublishers();

this._sender = output(args.sender);
this.identity = identity;

Expand Down Expand Up @@ -303,6 +327,27 @@ export class Email extends Component implements Link.Linkable {
});
}

function createIdentityPublishers() {
all([args.publishers, identity]).apply(([topic, identity]) => {
if (!topic) return;

const types = Array.from(Object.keys(topic)) as Array<
"Bounce" | "Complaint" | "Delivery"
>;

if (types.length === 0) return;
// i used map because i saw it above but shouldn't you use forEach?
types.map(
(event) =>
new ses.IdentityNotificationTopic(`${event}-Notification`, {
identity: identity.arn,
notificationType: event,
topicArn: topic[event]?.arn,
}),
);
});
}

function waitForVerification() {
new ses.DomainIdentityVerification(
`${name}Verification`,
Expand Down