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 Risposta
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
con risposta 8 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande