Search code examples
typescriptamazon-web-servicesaws-cdkamazon-ses

Bounce notifications for SES identity


Here's a snippet of my CDK TypeScript code that creates an SES identity and SNS topic:

  toolsAccountSES = new EmailIdentity(this, 'ToolsSESidentity', {
    identity: Identity.publicHostedZone(hostedZone),
  });

  // setting up bounce notifications
  const bounceTopic = new Topic(this, `ses-bounce-${props.branchName}`, {
    topicName: `ses-bounce-${props.branchName}`,
    displayName: `SES bounce notifications for ${props.branchName}`,
  });

  bounceTopic.addSubscription(new EmailSubscription(bounceEmail))

Is there a way to add this topic to the identity to receive bounce notifications? I couldn't find a way to do this in CDK

UPDATE: Code for attempted solution

I've created a construct that creates the configuration set

export class sesConfig extends Construct {
  public configurationSet: ConfigurationSet;

  constructor(scope: Construct, id: string) {
    super(scope, id);

    const bounceTopic = new Topic(this, 'bounce-topic');
    bounceTopic.addSubscription(new EmailSubscription(bounceEmail));

    this.configurationSet = new ConfigurationSet(this, 'ses-config');

    this.configurationSet.addEventDestination('bounce-destination', {
      destination: EventDestination.snsTopic(bounceTopic),
      events: [EmailSendingEvent.BOUNCE],
    });
;
  }
}

And I pass it to the constructor when creating the email identity

    new EmailIdentity(scope, 'SubdomainIdentity', {
      identity: Identity.publicHostedZone(hostedZone),
      configurationSet: new sesConfig(scope, 'ses-config').configurationSet, 
    });

Email identity is created, and so is the SNS topic, but when I look at the identity in the console - no notification is set

enter image description here


Solution

  • Add a configurationSet prop to your EmailIdentity construct. A Configuration Set is a group of rules that are applied to an identity. Instatiate a ConfigurationSet construct. Add a ConfigurationSetEventDestination with the addEventDestination method. Configure your destination to use your SNS topic for the desired events (like BOUNCE or COMPLAINT).

    See also the CloudFormation docs for AWS::SES::ConfigurationSet and AWS::SES::ConfigurationSetEventDestination. The AWS blog post Amazon SES – Set up notifications for bounces and complaints discusses Configuration Sets.