amazon-web-servicesamazon-cloudwatchcloudwatch-alarms

Creating cloudwatch alarm based on lambda duration metric using cloudformation


I was able to create a cw alarm based on the duration metric (raise alarm if lambda runs for over a minute) using the GUI. But I was wondering how to do this with cloudformation. So far, I have this -

Resources:
  testAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: test-alarm
      AlarmDescription: "I'm taking too long!"
      ComparisonOperator: GreaterThanThreshold
      EvaluationPeriods: 1
      DatapointsToAlarm: 1
      MetricName: Duration
      Namespace: aws/lambda
      Period: 60
      Statistic: Maximum
      Threshold: 0
      Dimensions:
        - Name: 'FunctionName'
          Value: 'hello world'
      TreatMissingData: notBreaching

I am not able to link the duration metric of the lambda function. I tried doing that with the dimensions above but it understandably doesn't work. Any help would be strongly appreciated!

Edit - doesn't work as in the alarm doesn't turn on, the threshold is 0, so if the duration>0 which I do with time.sleep, the alarm should be active. But there is no change and the graph doesn't depict duration in the test runs. It does so for the alarm I created with the web console.


Solution

  • Based on the comments, the issue was that it should be:

    Namespace: AWS/Lambda
    

    rather then

    Namespace: aws/lambda