英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论