当 API 网关调用达到其 29 秒超时和 returns 504 错误时触发 AWS 警报

Trigger an AWS Alarm when an API Gateway invocation hits its 29 second timeout and returns a 504 error

我是云中的新手,我需要配置 CloudWatch 以在出现 504 错误时调用 Lambda。为此,我在下面编写了无服务器代码:但是在出现 504 错误时,代码没有调用警报。在代码中,我定义了 29000 毫秒(29 秒)阈值,任何花费时间超过或等于的请求都应调用警报。

请帮我弄清楚我在这里遗漏了什么?

 TaskTimeoutAlarm:
  Type: AWS::CloudWatch::Alarm
  Properties:
    Namespace: "AWS/ApiGateway"
    MetricName: "Latency"
    AlarmDescription: "API Gateway timeout"
    Threshold: 29000
    Period: 300
    EvaluationPeriods: 1
    ComparisonOperator: "GreaterThanOrEqualToThreshold"
    AlarmActions:
      - arn:aws:sns:${self:provider.region}:${self:provider.awsAccountId}:${self:custom.alertSnsTopic}
    OKActions:
      - arn:aws:sns:${self:provider.region}:${self:provider.awsAccountId}:${self:custom.alertSnsTopic}
    TreatMissingData: "notBreaching"
    Statistic: "Maximum"
    Dimensions:
      - Name: environment
        Value: ${self:provider.stage}

已编辑 ----------

问题出在维度中传递的键值中。应该是这样

Dimensions:
      - Name: ApiName 
        Value: dev-employee-api
      - Name: Stage
        Value: dev

您的尺寸是否正确?您将名称声明为 "environment",您可能希望使用 "stage" 或者 ApiName。当您查看 CloudWatch 控制台中的指标时,您想要的维度名称是什么 "environment"?