amazon-cloudformation - How to reuse CloudFormation CodeBlocks?
问题描述
I wonder if there is a way for me to reuse codeblock in CloudFormation without copy and paste. For example: right now I am making a bunch of alarms for different Redis clusters, the only real difference is the CacheClusterId (cache-001 then cache-002, cache-003 in this case) itself. I have looked up the instruction but I couldn't find a good way to not Copy and Paste. Or is it possible to have array of values instead of single value
"CacheMemoryUsage001": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"MetricName": "DatabaseMemoryUsagePercentage"
...
}
"Dimensions": [{
"Name": "CacheClusterId",
"Value": "cache-001"
},
....
I would like to organize the template better, right now I have couple alarms type per cluster and they are getting messier to maintain and keep track of
解决方案
There are general two ways for that:
- Use nested stacks. In this case, definition of a common resource(s) would be put to a separate stack, and in the main stack you would use the nested stack to create multiple resources based on the nested stack.
- Create CFN macro which would perform basic find-and-replace type of your template processing to create the copies of the resources.
推荐阅读
- c# - 将 SQL 查询转换为 C#?对于存储过程?
- c++ - 从堆栈分配的原始指针构造智能指针
- c# - 使用 EPPlus.Core 在 Excel 文件中创建多个标题行
- python - Python中的三元运算符中是否可以进行多个变量赋值?
- sql - 带日期函数的 SQL 连接
- stm32 - STM32F103 SPI主从接收问题
- excel - 如何根据特定单元格中是否存在单词,将一个单元格的值替换为另一个单元格的值
- makefile - distcc - 是否存在需要同步网络文件系统的情况
- performance - 通过 _id 查询时,Cosmos DB 集合不使用 _id 索引?
- python - 按顺序获取大量(我说的是巨大的)ID列表的查询集的Django高性能方式