【发布时间】:2020-04-20 13:50:24
【问题描述】:
我想用 boto3 和数学表达式创建 Disk-Read-Throughput-IOPS cloudwatch 警报,但我有错误 错误 "errorMessage": "调用PutMetricAlarm操作时发生错误(ValidationError):参数MetricDataQuery Expression和MetricStat互斥,你都指定了。"
代码
from __future__ import print_function
from string import Template
import json
import boto3
def lambda_handler(event, context):
CW_client = boto3.client('cloudwatch', region_name='eu-west-1')
volume_id = 'vol-01903a31c2c4d5690'
response7 = CW_client.put_metric_alarm(
AlarmName='Disk-Read-Throughput-IOPS',
AlarmDescription='Disk-Read-Throughput-IOPS',
ActionsEnabled=True,
AlarmActions=[
'topic',
],
MetricName='VolumeReadOps',
Namespace='AWS/EBS',
Statistic='Sum',
Dimensions=[
{
'Name': 'VolumeId',
'Value': 'volume_id'
},
],
Period=300,
EvaluationPeriods=3,
DatapointsToAlarm=3,
Threshold=600.0,
ComparisonOperator='GreaterThanThreshold',
Metrics=[
{
'Id': 'm1',
'MetricStat': {
'Metric': {
'Namespace': 'AWS/EBS',
'MetricName': 'VolumeReadOps',
'Dimensions': [
{
'Name': 'VolumeId',
'Value': 'volume_id'
},
]
},
'Period': 300,
'Stat': 'Sum',
},
'Expression': 'SUM(METRICS())/300',
'Label': 'Expression1',
'Period': 300
},
],
)
【问题讨论】:
标签: python aws-lambda boto3 amazon-cloudwatch