How to pass tags of existing resources to cloud watch alarm in CFT in AWS?

Viewed 1180

I am trying to add a CloudWatch alarm over multiple instances in my AWS account based on the instance tags.

For example, I have 4 instances running with tags Name=DEV, APP=WebServer.

I am new to AWS CloudFormation templates, so I am not sure how to add the tags in the CloudWatch alarm's dimensions property. Can I attach a single alarm to multiple instances by referring to them by tags when I create the instances?

Here's a snippet from my template.

CPUAlarm:
  Type: AWS::CloudWatch::Alarm
  Properties:
    AlarmDescription: CPUtilization
    AlarmActions: "SNS TOPIC ARN"
    MetricName: CPUUtilization
    Namespace: AWS/EC2
    Statistic: Average
    Period: '60'
    EvaluationPeriods: '2'
    Threshold: '80'
    ComparisonOperator: GreaterThanThreshold
    Dimensions:
1 Answers

If you are creating the instances via CFN template, you can parameterize the tags and use the same parameters in your cloudwatch alarm resource

Related