I am new in the cloud and I have the requirement to configure CloudWatch to invoke a Lambda in case of 504 error. For that, I have written below Serverless code: But on 504 error, the code in not invoking the Alarm. In the code, I have defined 29000 milliseconds (29 seconds) threshold and any request taking time more than or equal to should invoke Alarm.
Please help me to figure out what am I missing here?
TaskTimeoutAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
Namespace: "AWS/ApiGateway"
MetricName: "Latency"
AlarmDescription: "API Gateway timeout"
Threshold: 29000
Period: 300
EvaluationPeriods: 1
ComparisonOperator: "GreaterThanOrEqualToThreshold"
AlarmActions:
- arn:aws:sns:${self:provider.region}:${self:provider.awsAccountId}:${self:custom.alertSnsTopic}
OKActions:
- arn:aws:sns:${self:provider.region}:${self:provider.awsAccountId}:${self:custom.alertSnsTopic}
TreatMissingData: "notBreaching"
Statistic: "Maximum"
Dimensions:
- Name: environment
Value: ${self:provider.stage}
Edited -----------
The problem was in the key-value passed in Dimensions. This is how it should be
Dimensions:
- Name: ApiName
Value: dev-employee-api
- Name: Stage
Value: dev
Is your Dimensions correct? You state the name as "environment", you may want to use "stage" or maybe ApiName. When you look at the metric in the CloudWatch Console, what is the name of the dimension you want "environment"?