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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南