Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Lambda alarm for specific Lambda using CloudFormation?

This is the structure of CloudFormation Alarm from AWS document.

Type: "AWS::CloudWatch::Alarm"
Properties:
  ActionsEnabled: Boolean
  AlarmActions:
    - String
  AlarmDescription: String
  AlarmName: String
  ComparisonOperator: String
  Dimensions:
    - Dimension
  EvaluateLowSampleCountPercentile: String
  EvaluationPeriods: Integer
  ExtendedStatistic: String
  InsufficientDataActions:
    - String
  MetricName: String
  Namespace: String
  OKActions:
    - String
  Period: Integer
  Statistic: String
  Threshold: Double
  TreatMissingData: String
  Unit: String

However, It seems to set an alarm for the total lambda functions metric's figure, not for only specific function and I couldn't find any mention about setting an alarm for a specific function.

How could I set an alarm for a specific function?

like image 662
SangminKim Avatar asked Jul 06 '18 02:07

SangminKim


People also ask

How do you get notified on a specific Lambda function error?

Amazon CloudWatch alarms are used to notify when an error occurs with a Lambda function; this notification does not give any specifics about the error. For scenarios where you need specificity on the error in the notification, you can use a CloudWatch Logs subscription.

How do you trigger Lambda function in CloudFormation?

AWS CloudFormation invokes your Lambda function asynchronously with an event that includes a callback URL. The function is responsible for returning a response to the callback URL that indicates success or failure. For the full response syntax, see Custom resource response objects.


1 Answers

To alarm on a specific lambda function's metric you have to set the FunctionName dimension.

Like this for example:

  MyNewAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: "AlarmNameGoesHere"
      AlarmDescription: "Alarm if lambda errors out too many times"
      Namespace: "AWS/Lambda"
      MetricName: "Errors"
      Dimensions:
      - Name: "FunctionName"
        Value: "NameOfYourLambdaFunction"
      Statistic: "Sum"
      ComparisonOperator: "GreaterThanThreshold"
      Threshold: 0
      EvaluationPeriods: 5
      Period: 60
      TreatMissingData: "breaching"
like image 83
Dejan Peretin Avatar answered Sep 28 '22 00:09

Dejan Peretin