# Create CloudWatch Alarm to trigger multiple Lambda functions

**URL:** <https://forum.serverless.com/t/create-cloudwatch-alarm-to-trigger-multiple-lambda-functions/19957>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, cloudformation\
**Created:** [February 20, 2024, 4:58pm UTC](https://forum.serverless.com/t/create-cloudwatch-alarm-to-trigger-multiple-lambda-functions/19957 "2024-02-20T16:58:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpardess](https://avatars.discourse-cdn.com/v4/letter/h/919ad9/32.png) [@hpardess](https://forum.serverless.com/u/hpardess)\
**Post date:** [February 20, 2024, 4:58pm UTC](https://forum.serverless.com/t/create-cloudwatch-alarm-to-trigger-multiple-lambda-functions/19957/1 "2024-02-20T16:58:16Z")

</div>

I would like to implement following in Serverless framework.

 ![Screenshot 2024-02-16 at 4.22.22 PM](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/2X/d/d8373cc75afdba9dcab8759cffd46e9f9d2754c3.jpeg)

I have multiple services and each serverless service has multiple lambda functions. I would like to trigger the CloudWatch alarm by all Lambda functions that fails or throw exception.

Here is the code to be triggered by one lambda function:

```auto
resources:
  Resources:
    TopicAlarm4xx:
      Type: AWS::SNS::Topic
      Properties:
        TopicName: error_notification_topic

    LambdaAlarm4xx:
      Type: AWS::CloudWatch::Alarm
      Properties:
        AlarmDescription: 4xx errors detected at Lambda
        Namespace: AWS/Lambda
        MetricName: 4XXErrors
        Statistic: Sum
        Threshold: 1
        ComparisonOperator: GreaterThanOrEqualToThreshold
        EvaluationPeriods: 1
        Period: 300
        Dimensions:
          - Name: LambdaName
            Value: # Value: !Ref LambdaName
              Ref: functionName

```

---

<div class="post-metadata">

**Author:** ![hpardess](https://avatars.discourse-cdn.com/v4/letter/h/919ad9/32.png) [@hpardess](https://forum.serverless.com/u/hpardess)\
**Post date:** [February 20, 2024, 4:59pm UTC](https://forum.serverless.com/t/create-cloudwatch-alarm-to-trigger-multiple-lambda-functions/19957/2 "2024-02-20T16:59:19Z")

</div>

[![](https://img.youtube.com/vi/sydhU7sIgN0/maxresdefault.jpg "How To Create a CloudWatch Alarm for a Lambda Using the AWS Console and Serverless Framework") ](https://www.youtube.com/watch?v=sydhU7sIgN0)

---

<div class="post-metadata">

**Author:** ![hpardess](https://avatars.discourse-cdn.com/v4/letter/h/919ad9/32.png) [@hpardess](https://forum.serverless.com/u/hpardess)\
**Post date:** [February 20, 2024, 4:59pm UTC](https://forum.serverless.com/t/create-cloudwatch-alarm-to-trigger-multiple-lambda-functions/19957/3 "2024-02-20T16:59:56Z")

</div>

[![](https://img.youtube.com/vi/-L5Tbo3P5HA/maxresdefault.jpg "How to Alert Production Errors in Real-Time for Serverless Apps") ](https://www.youtube.com/watch?v=-L5Tbo3P5HA)

---

<div class="post-metadata">

**Author:** ![hpardess](https://avatars.discourse-cdn.com/v4/letter/h/919ad9/32.png) [@hpardess](https://forum.serverless.com/u/hpardess)\
**Post date:** [March 13, 2024, 5:26am UTC](https://forum.serverless.com/t/create-cloudwatch-alarm-to-trigger-multiple-lambda-functions/19957/4 "2024-03-13T05:26:29Z")

</div>

Here is how it works for one lambda function

```auto
service: TestService

plugins:
  - serverless-pseudo-parameters

custom:
  stage: dev
  log_notification: "log_notification_${self:custom.stage}"

provider:
  iamRoleStatements:
    - Effect: "Allow"
        Action: 
          - logs:*
        Resource: "arn:aws:logs:*:*:*"
    - Effect: 'Allow'
        Action:
          - "sns:*"
        Resource: "*"

functions:
  logNotification:
      handler: handler.logNotification
      events:
        - sns: arn:aws:sns:#{AWS::Region}:#{AWS::AccountId}:${self:custom.log_notification}
  testError:
      handler: handler.testError
      events:
        - http:
            path: testerror
            method: get
            cors: true

resources:
  Resources:
    TopicAlarmLambdaError:
      Type: AWS::SNS::Topic
      Properties:
        TopicName: ${self:custom.log_notification}

    LambdaAlarmForErrors:
      Type: AWS::CloudWatch::Alarm
      Properties:
        AlarmDescription: Lambda errors detected in All Lambdas
        Namespace: AWS/Lambda
        MetricName: Errors
        Statistic: Sum
        Threshold: 1
        ComparisonOperator: GreaterThanOrEqualToThreshold
        EvaluationPeriods: 1
        Period: 30 # seconds
        AlarmActions:
          - Ref: TopicAlarmLambdaError
        Dimensions:
          - Name: FunctionName
            Value: ${self:service}-${self:custom.stage}-testError

```
