AWS::CloudWatch::Alarm Dimension - AWS CloudFormation
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

AWS::CloudWatch::Alarm Dimension

Dimension 是 AWS::CloudWatch::Alarm 类型的嵌入式属性。维度是可与 CloudWatch 指标关联的名称/值对。您最多可以为给定指标指定 10 个维度。

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

JSON

{ "Name" : String, "Value" : String }

YAML

Name: String Value: String

属性

Name

维度的名称,长度在 1–255 个字符之间。发布度量时,必须包含此维度名称。

必需:是

类型:字符串

最低1

最高255

Update requires: No interruption

Value

维度的值,长度在 1–255 个字符之间。

必需:是

类型:字符串

最低1

最高255

Update requires: No interruption

示例

两个 CloudWatch 警报,具有 Ref 函数提供的维度值

RefGetAtt 内部函数通常用于为 CloudWatch 指标维度提供值。下面是 Ref 函数的使用示例。

JSON

{ "CPUAlarmHigh": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "AlarmDescription": "Scale-up if CPU is greater than 90% for 10 minutes", "MetricName": "CPUUtilization", "Namespace": "AWS/EC2", "Statistic": "Average", "Period": "300", "EvaluationPeriods": "2", "Threshold": "90", "AlarmActions": [ { "Ref": "WebServerScaleUpPolicy" } ], "Dimensions": [ { "Name": "AutoScalingGroupName", "Value": { "Ref": "WebServerGroup" } } ], "ComparisonOperator": "GreaterThanThreshold" } }, "CPUAlarmLow": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "AlarmDescription": "Scale-down if CPU is less than 70% for 10 minutes", "MetricName": "CPUUtilization", "Namespace": "AWS/EC2", "Statistic": "Average", "Period": "300", "EvaluationPeriods": "2", "Threshold": "70", "AlarmActions": [ { "Ref": "WebServerScaleDownPolicy" } ], "Dimensions": [ { "Name": "AutoScalingGroupName", "Value": { "Ref": "WebServerGroup" } } ], "ComparisonOperator": "LessThanThreshold" } } }

YAML

CPUAlarmHigh: Type: 'AWS::CloudWatch::Alarm' Properties: AlarmDescription: Scale-up if CPU is greater than 90% for 10 minutes MetricName: CPUUtilization Namespace: AWS/EC2 Statistic: Average Period: '300' EvaluationPeriods: '2' Threshold: '90' AlarmActions: - !Ref WebServerScaleUpPolicy Dimensions: - Name: AutoScalingGroupName Value: !Ref WebServerGroup ComparisonOperator: GreaterThanThreshold CPUAlarmLow: Type: 'AWS::CloudWatch::Alarm' Properties: AlarmDescription: Scale-down if CPU is less than 70% for 10 minutes MetricName: CPUUtilization Namespace: AWS/EC2 Statistic: Average Period: '300' EvaluationPeriods: '2' Threshold: '70' AlarmActions: - !Ref WebServerScaleDownPolicy Dimensions: - Name: AutoScalingGroupName Value: !Ref WebServerGroup ComparisonOperator: LessThanThreshold