DanielDaCosta / cloudwatch-alarms

CloudWatch-SNS-Lambda integration that sends alarm notification to discord channel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloudwatch Alarms with SNS topic

This repository contains the following topics:

  • Cloudwatch alarms resources to be created based on the lambda name.
  • SNS topic that will be triggered by the alarm
  • Lambda-alarm that will send the message received from SNS to a Discord channel through a WEBHOOK_URL

Files

  • lambda/*: Contains the lambda-alarm zip code that is stored in s3
  • sns.tf: creates SNS topic
  • iam.tf: Lambda permission
  • lambda-alarm: Containes lambda-alarm tf file
  • cloudwatch.tf: creates alarms

Usage

terraform apply -var-file="variables.tfvars"

CloudWatch alarms

In this example, the service that is being monitored is: AWS Lambda, but you can easily use it to monitor others services (SQS, ECS, EC2, ...).

If you'd like to add a new lambda to me monitored you just have to add it in the following local variable:

locals {
  name_dash = "${var.name}-${var.environment}"
  # Lambda with Alarms
  alarms_dimensions = {
    "${var.name}-${var.environment}-lambda-1" = {
      FunctionName = "${var.name}-${var.environment}-lambda-1"
    },
    "lambda-2" = {
      FunctionName = "lambda-y"
    },
    "lambda-3" = {
      FunctionName = "lambda-z"
    },
    "new-lambda" = {
      FunctionName = "NEW-LAMBDA"
    }
  }
}

SNS topic

You will just have to create a SNS topic and link it with your lambda-alarm.

Lambda-Alarm

This lambda zip is stored in a s3 bucket. You can find lambda's code inside the folder lambda

Medium Post

More details on my Medium Post: Discord notification using CloudWatch Alarms, SNS and AWS Lambda

References

About

CloudWatch-SNS-Lambda integration that sends alarm notification to discord channel

License:Apache License 2.0


Languages

Language:Python 99.7%Language:HCL 0.3%