Serverless wrapper to setup CloudWatch Alarms for SQS
Clone or download
gcphost and sbstjn Specify Period and EvaluationPeriods (#10)
* Specify Period and EvaluationPeriods #7

* fix linting

* add namespace to properties
Latest commit 0918825 May 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Specify Period and EvaluationPeriods (#10) May 5, 2018
test Specify Period and EvaluationPeriods (#10) May 5, 2018
.gitignore Add basic test Mar 31, 2017
.npmignore Add .npmignore Mar 31, 2017
LICENSE.md Initial commit. Mar 31, 2017
README.md Update README.md Jun 9, 2017
circle.yml Run `yarn lint` before running tests … Jun 9, 2017
package.json Update package.json Jun 9, 2017
yarn.lock Add dot-json to devDependencies Jun 9, 2017

README.md

⚡️ 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 😘