amazon-cloudwatchaws-cdkamazon-sns

how to add multiple email to sns subscription


I am trying to add multiple email address in cdk code for sns subscription but getting error as Invalid parameter email address. When i tried with one email address then it works without issue.

// Adding an SNS action and an email registration 
const notificationsTopic = new Topic(this, 'Topic'); 
numFailedJobsAlarm.addAlarmAction(new SnsAction(notificationsTopic));
notificationsTopic.addSubscription(new EmailSubscription('rd@bak.de, ak@bak.de')); 

How can i add multiple email address in sns subscription ?


Solution

  • An SNS email subscription has a single email target. If you want to target more than one email, you need to create more than one subscription.

    const emails = ['rd@bak.de', 'ak@bak.de'];
    
    emails.forEach((email) => {
        notificationsTopic.addSubscription(new EmailSubscription(email));
    });