我正在尝试为Lambda执行设置cloudwatch警报。我可以设置ALARM和OK for Error。但是,只要我的代码中出现语法错误,我就会收到INSUFFICIENT_DATA警报。
我在下面添加了我的代码:
import json
import sys
print "Buckle your seat belt even if you are in back seat"
def lambda_handler(event, context):
try:
print( "value 1 = " + event['key'])
print( "value 2 = " + event['key2'])
print( "value 3 = " + event['key3'])
return event['key1']
except Exception as e:
print sys.exc_info()[0]
raise
测试数据:
{“key3”:“value3”,“key2”:“value2”,“key1”:“value1”}
以下是我生成的错误:
{
"stackTrace": [
[
"/var/task/lambda_function.py",
6,
"lambda_handler",
"print( \"value 1 = \" + event['key'])"
]
],
"errorType": "KeyError",
"errorMessage": "'key'"
}
我可以为KeyError创建一个指标过滤器并设置我的警报。但我想为所有错误创建一个单一的警报,无论是系统级别如lambda执行还是代码级别如KeyError等。 任何人都可以帮我如何捕获云计算的单一警报中的语法错误或数据错误?
由于