Search code examples
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('[email protected], [email protected]')); 

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 = ['[email protected]', '[email protected]'];
    
    emails.forEach((email) => {
        notificationsTopic.addSubscription(new EmailSubscription(email));
    });