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 Answer
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
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions