在 CloudFormation 中为 APIGateway 方法设置 CloudWatch 维度

Setting up CloudWatch dimensions for APIGateway methods in CloudFormation

我有一个 api 说 apifortest,它在不同路径下有 10 个方法。这些方法是 GETPUTPOST。我想要做的是为这些创建一个 CloudWatch 监视器。

我正在看这里的文档

http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/api-gateway-metrics-dimensions.html

这是我之前的

TestApiCloudWatch:
    Type: "AWS::CloudWatch::Alarm"
    Properties:
        ActionsEnabled: "True"
        AlarmName: "ApiGateway-TestAPI-5XXError-SEV2"
        ComparisonOperator: !FindInMap [APIGatewayCloudWatchMappings, 5XXError-SEV2, ComparisonOperator]
        Dimensions:
            -
                Name: "ApiName"
                Value: "APIForTest"
            -
                Name: "Stage"
                Value: "Prod"
        EvaluationPeriods: !FindInMap [APIGatewayCloudWatchMappings, 5XXError-SEV2, EvaluationPeriods]
        MetricName: !FindInMap [APIGatewayCloudWatchMappings, 5XXError-SEV2, MetricName]
        Namespace: "AWS/ApiGateway"
        Period: !FindInMap [APIGatewayCloudWatchMappings, 5XXError-SEV2, Period]
        Statistic: !FindInMap [APIGatewayCloudWatchMappings, 5XXError-SEV2, Statistic]
        Threshold: !FindInMap [APIGatewayCloudWatchMappings, 5XXError-SEV2, Threshold]

但是此警报正在设置 在 API 级别 。我想在方法级别设置。该文档确实说明我们可以这样做,但没有任何示例。

如有任何帮助,我们将不胜感激。

文档列出了您需要使用的维度:

  • API 名称 - API 的名称。你已经有了这个。
  • 舞台 - API 舞台的名称。你已经有了这个。
  • 方法 - HTTP 方法(例如 GET、PUT、DELETE)
  • Resource - 资源路径(例如/foo/bar)