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

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

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:

  1. "dlqAlertAddress": {
  2. "alertaddress": [
  3. "xyz@example.com",
  4. "abc@example.com"
  5. ]
  6. }

This is how I am extracting and passing it down to the CDK stack:

  1. const dlqAlertAddress: {
  2. alertaddress: string[];
  3. } = app.node.tryGetContext("dlqAlertAddress");
  4. console.log(dlqAlertAddress);
  5. slackNotificationEbPipe.dlqTopic.addSubscription(
  6. new subscriptions.EmailSubscription(props.dlqAlertAddress.alertaddress)
  7. );

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

  1. "dlqAlertAddress": {
  2. "alertaddress": [
  3. "xyz@example.com",
  4. "abc@example.com"
  5. ]
  6. }

This is How I am extracting and passing it down to cdk stack.

  1. const dlqAlertAddress: {
  2. alertaddress: string[];
  3. } = app.node.tryGetContext("dlqAlertAddress");
  4. console.log(dlqAlertAddress)
  5. slackNotificationEbPipe.dlqTopic.addSubscription(
  6. new subscriptions.EmailSubscription(props.dlqAlertAddress.alertaddress)
  7. );

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 函数解决了它

  1. props.dlqAlerts.mailAddress.map((address, index) => {
  2. return new sns.Subscription(scope, `${alertAdressMapId}-${index}`, {
  3. topic: dlqTopic,
  4. protocol: sns.SubscriptionProtocol.EMAIL,
  5. endpoint: address,
  6. });
  7. });
英文:

I solved it using map function

  1. props.dlqAlerts.mailAddress.map((address, index) => {
  2. return new sns.Subscription(scope, `${alertAdressMapId}-${index}`, {
  3. topic: dlqTopic,
  4. protocol: sns.SubscriptionProtocol.EMAIL,
  5. endpoint: address,
  6. });
  7. });

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:

确定