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
2
Answers
There are general two ways for that:
Besides the already mentioned methods, you can use CodePipeline with CodeBuild.
Use the AWS CDK to dynamically (using for instanve standard python code) create the CF template in CodeBuild and then pass it to a CloudFormation deploy stage which deploys the previous generated template.
https://aws.amazon.com/cdk/
Secondly using StackSets is an option if you want to deploy one template in multiple regions, accouts or organization OU level from one central place!
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html