如何为 lambda 超时设置 cloudwatch 警报?

How to set up an cloudwatch alarm for lambda timeout?

我有一个通过 cloudformation 模板创建的 lambda。我已经设置了我的内存大小和超时时间。如果 lambda 超时,我想发出警报。我知道要为下面的警报设置什么指标名称、统计信息和其他值

Resources: 
  someLambda:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: "MyFunct"
      Description: "..."
      MemorySize: 512
      Timeout: 500
   
 timeoutAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: "timeout"
      AlarmDescription: "Alarm if lambda times out"
      MetricName: ...
      Dimensions:
      - Name: "FunctionName"
        Value: MyFunct
      Statistic: ...

没有超时指标。您执行此操作的唯一方法是在您的函数日志上设置 metric filter,以搜索超时消息。然后你就可以根据这样的过滤器创建一个警报。