如何从 CDK 上下文传递电子邮件地址数组并订阅 SNS 主题。

huangapple go评论59阅读模式
英文:

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,
    });
  });

huangapple
  • 本文由 发表于 2023年5月7日 19:04:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193531.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定