AWS CloudFormation – 如何将 SNS 主题 ARN 传递给堆栈?

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

AWS Cloudformation - How to pass the sns topic arn to a stack?

问题

我正在创建一个CloudFormation模板,允许在CloudFormation堆栈创建、更新、删除等过程中向用户发送SNS通知(电子邮件)。

如何使用'无服务器框架'创建一个堆栈,但传递给它一个SNS主题的ARN。

我想要做类似这样的事情:

aws cloudformation create-stack \
--stack-name my-cloudformation \
--template-body file://test.yaml \
--notification-arns ${SNS_TOPIC_ARN}

谢谢。

英文:

I'm creating a CloudFormation template that allows sending SNS notifications (emails) to users during creation, update, deletion, etc. from the CloudFormation stack.

How can you create a stack using the 'serverless framework' but passing it the arn of a sns topic.

I want to do something like this

aws cloudformation create-stack \
--stack-name my-cloudformation \
--template-body file://test.yaml \
--notification-arns ${SNS_TOPIC_ARN}

Thank you.

答案1

得分: 1

第一种方法是在CloudFormation模板中使用参数,并通过--parameters选项将ARN作为参数传递:

aws cloudformation create-stack \
--stack-name my-cloudformation \
--template-body file://test.yaml \
--parameters ParameterKey=SNS_TOPIC_ARN,ParameterValue=${SNS_TOPIC_ARN}

第二种方法是假设SNS主题也是从CloudFormation模板创建的(推荐使用IaC优势),将SNS主题的ARN(这是CloudFormation输出)存储到Parameter Store中,甚至直接导出它。然后直接从您提到的CloudFormation模板中检索其值。但是这会创建堆栈之间的依赖关系。

英文:

You have basically two options:

First one is using parameters in the CloudFormation template, and passing the ARN as a parameter in the call through --parameters:

aws cloudformation create-stack \
--stack-name my-cloudformation \
--template-body file://test.yaml \
--parameters ParameterKey=SNS_TOPIC_ARN,ParameterValue=${SNS_TOPIC_ARN}

The second one is, assuming the SNS topic has been also created from a CloudFormation template (recommended for IaC advantages), to store the ARN of the SNS topic (which is a CloudFormation Output) into the Parameter Store, or even directly exporting it. And then retrieving its value directly from the CloudFormation template you mention. However this creates a dependency between stacks.

huangapple
  • 本文由 发表于 2023年6月2日 12:40:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76387147.html
匿名

发表评论

匿名网友

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

确定