I have 2 email adress which are defined as array In cdk context. How do I subscribe to sns topic.
Here my cdk context
"dlqAlertAddress": {
"alertaddress": [
"[email protected]",
"[email protected]"
]
}
This is How I am extracting and passing it down to cdk stack.
const dlqAlertAddress: {
alertaddress: string[];
} = app.node.tryGetContext("dlqAlertAddress");
console.log(dlqAlertAddress)
slackNotificationEbPipe.dlqTopic.addSubscription(
new subscriptions.EmailSubscription(props.dlqAlertAddress.alertaddress)
);
Error : Argument of type 'string[]' is not assignable to parameter of type 'string'.
I dont want to pass it as individual email address and pass 2 values, that is why I am looking for a solution which can help me achieve the same using array
I solved it using map
function
props.dlqAlerts.mailAddress.map((address, index) => {
return new sns.Subscription(scope, `${alertAdressMapId}-${index}`, {
topic: dlqTopic,
protocol: sns.SubscriptionProtocol.EMAIL,
endpoint: address,
});
});