英文:
How to pass an array of email adress from cdk context and subscribe to sns topic
问题
I have 2 email addresses defined as an array in the CDK context. How do I subscribe to an SNS topic?
Here's my CDK context:
"dlqAlertAddress": {
"alertaddress": [
"xyz@example.com",
"abc@example.com"
]
}
This is how I am extracting and passing it down to the 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 a parameter of type 'string'.
I don't want to pass it as individual email addresses and pass 2 values. That's why I'm looking for a solution that can help me achieve the same using an array.
英文:
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": [
"xyz@example.com",
"abc@example.com"
]
}
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
答案1
得分: 0
我使用 map
函数解决了它
props.dlqAlerts.mailAddress.map((address, index) => {
return new sns.Subscription(scope, `${alertAdressMapId}-${index}`, {
topic: dlqTopic,
protocol: sns.SubscriptionProtocol.EMAIL,
endpoint: address,
});
});
英文:
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,
});
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论