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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠