Giter Site home page Giter Site logo

sbstjn / serverless-sqs-alarms-plugin Goto Github PK

View Code? Open in Web Editor NEW
36.0 5.0 21.0 61 KB

Serverless wrapper to setup CloudWatch Alarms for SQS

Home Page: https://www.npmjs.com/package/serverless-sqs-alarms-plugin

License: MIT License

JavaScript 100.00%
serverless sqs aws lambda sns plugin

serverless-sqs-alarms-plugin's Introduction

⚡️ Serverless Plugin for SQS CloudWatch Alarms

npm CircleCI license Coveralls

About the plugin

This serverless plugin is a wrapper to configure CloudWatch Alarms to monitor the visible messages in an SQS queue. You need to provide the SQS queue name and SNS topic which will receive the Alarm and OK messages.

Usage

Add the npm package to your project:

# Via yarn
$ yarn add serverless-sqs-alarms-plugin

# Via npm
$ npm install serverless-sqs-alarms-plugin --save

Add the plugin to your serverless.yml:

plugins:
  - serverless-sqs-alarms-plugin

Configure alarms in serverless.yml:

custom:
  sqs-alarms:
    - queue: your-sqs-queue-name
      topic: your-sns-topic-name
      name: your-alarm-name # optional parameter
      thresholds:
        - 1
        - 50
        - 100
        - 500
      treatMissingData: string | array[] # optional parameter

The treatMissingData setting can be a string which is applied to all alarms, or an array to configure alarms individually. Valid types are ignore, missing, breaching, notBreaching, more details in the AWS docs …

That's it! With this example your SNS topic will receive a message when there are more than 1, 50, 100, and 500 visible in SQS.

CloudWatch Alarms

The created CloudWatch Alarms look like this:

{
  "Type": "AWS::CloudWatch::Alarm",
  "Properties": {
    "AlarmDescription": "Alarm if queue contains more than 100 messages",
    "Namespace": "AWS/SQS",
    "MetricName": "ApproximateNumberOfMessagesVisible",
    "Dimensions": [
      {
        "Name": "QueueName",
        "Value": "your-sqs-queue-name"
      }
    ],
    "Statistic": "Sum",
    "Period": 60,
    "EvaluationPeriods": 1,
    "Threshold": 100,
    "ComparisonOperator": "GreaterThanOrEqualToThreshold",
    "AlarmActions": [
      { "Fn::Join": [ "", [ "arn:aws:sns:eu-west-1:", { "Ref": "AWS::AccountId" }, ":your-sns-topic-name" ] ] }
    ],
    "OKActions": [
      { "Fn::Join": [ "", [ "arn:aws:sns:eu-west-1:", { "Ref": "AWS::AccountId" }, ":your-sns-topic-name" ] ] }
    ]
  }
}

License

Feel free to use the code, it's released using the MIT license.

Contribution

Feel free to contribute to this project! Thanks 😘

serverless-sqs-alarms-plugin's People

Contributors

gcphost avatar iodine- avatar partyschaum avatar sbstjn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

serverless-sqs-alarms-plugin's Issues

Question - Trigger fails sometimes

Hello @sbstjn,

This is more of a question than an issue I think. I'm using this plugin for Fifo queues because it's the only way to use them. Sometimes I check the queue and I have some messages that have been there a long time.
My fifo queue has a delay of 300s to avoid duplicates during those 5 minutes next to the message sent to the queue and the threshold I have set up is:

thresholds:
        - 1
        - 2
        - 3
        - 4
        - 10

How is possible that the lambda function is not triggered?

Fails when queue name is intrinsic function

Using ImportValue for queue name as following:

sqs-alarms:

- thresholds: [1, 10, 50, 100]
  queue: { 'Fn::ImportValue': "create-events:MyQueueName" }
  topic: "AlarmsTopicName"

Fails with the following error: this.queue.replace is not a function

It'd be useful to be able to specify Period and/or EvaluationPeriods

Proposed syntax:

custom:
  sqs-alarms:
    - queue: your-sqs-queue-name
      topic: your-sns-topic-name
      name: your-alarm-name # optional parameter
      thresholds:
        - value: 1
          period: 60
          evaluationPeriods: 5

But this looks like it would be a breaking change... So maybe being able to set Period and/or EvaluationPeriods just once for all thresholds is enough?

custom:
  sqs-alarms:
    - queue: your-sqs-queue-name
      topic: your-sns-topic-name
      name: your-alarm-name # optional parameter
      thresholds:
        - 1
      period: 60
      evaluationPeriods: 5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.