Considering the following CloudWatch alert on an API Gateway:
LatencyAlarmP90:
Type: AWS::CloudWatch::Alarm
Condition: Production
Properties:
AlarmDescription: latency P90 is lower then 1.5 sec
AlarmName: FooApiP90LatencyAlarm
ComparisonOperator: GreaterThanOrEqualToThreshold
ExtendedStatistic: "p90"
Period: 300
MetricName: "Latency"
DatapointsToAlarm: 5
EvaluationPeriods: 5
Threshold: 1500
Namespace: AWS/ApiGateway
Dimensions:
- Name: ApiName
Value: !Sub "bar"
AlarmActions:
- Fn::ImportValue: !Sub "foo"
OKActions:
- Fn::ImportValue: !Sub foo"
If this alert triggers, I have no way of knowing which specific route triggered it (multiple lambdas are on the same API Gateway).
I was thinking about monitoring each Lambda instead.
If I monitor a specific Lambda latency does it include API Gateway latency? (Cold starts) or only run time?
If not, is there a way to monitor a specific route/Lambda including API Gateway latency?
CodePudding user response:
If I monitor a specific Lambda latency, does it include API Gateway latency?
No.
The Duration
performance metric does not include any API Gateway latency & is only Lambda function run time rounded up to the nearest millisecond as per docs.
If not, is there a way to monitor a specific route/Lambda including API Gateway latency?
Per route yes, per Lambda no.
For a metric that also includes API Gateway overhead, use the Latency
metric for API GW.
Per Lambda function is not a supported dimension to assign to the metric and thus filter by but you can achieve the end result by using various other dimensions - including route - to filter this down.
Inevitably, you will need more alarms if the same Lambda function is responsible for multiple routes.
You will have to filter down your alarm by:
- Method
- ApiId & Stage
- Stage
- ApiId
- Api Name