Error metrics for API Gateway resource

0

I am trying to create CloudWatch alarms for specific API Gateway methods. I am using the Javascript CDK.

I can create alarms at the "API" level and get the expected alarms using the following code. These work as expected.

new Alarm(this, 'test-api-alarm', {
   metric: api.metricClientError(),
   threshold: 1,
   comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
   treatMissingData: TreatMissingData.NOT_BREACHING,
   evaluationPeriods: 1,
   alarmDescription: 'Alarm if the SUM of Errors is greater than or equal to the threshold (1) for 1 evaluation period',
})

I cannot seem to get the metrics at the method level. I see the alarm triggering for the API but not the method. In the console it appears like the "metricClientError" function on the API Method is creating the proper metric for the alarm but since it doesn't work it's unclear what is misconfigured. Are metrics at the method level not actually supported by CloudWatch and/or API Gateway?

const method = api.addMethod('GET', testLambda)

new Alarm(this, 'test-method-called-alarm', {
   metric: method.metricClientError(method.api.deploymentStage),
   threshold: 1,
   comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
   treatMissingData: TreatMissingData.NOT_BREACHING,
   evaluationPeriods: 1,
   alarmDescription: 'Alarm if the SUM of Errors is greater than or equal to the threshold (1) for 1 evaluation period',
})
1 回答
0

I figured it out.

"API Gateway will not send these metrics unless you have explicitly enabled detailed CloudWatch metrics. You can do this in the console by selecting Enable Detailed CloudWatch Metrics under a stage Logs/Tracing tab. Alternatively, you can call the update-stage AWS CLI command to update the metricsEnabled property to true."

Austin
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则