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
lambda/*
: Contains the lambda-alarm zip code that is stored in s3sns.tf
: creates SNS topiciam.tf
: Lambda permissionlambda-alarm
: Containes lambda-alarm tf filecloudwatch.tf
: creates alarms
terraform apply -var-file="variables.tfvars"
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"
}
}
}
You will just have to create a SNS topic and link it with your lambda-alarm.
This lambda zip is stored in a s3 bucket. You can find lambda's code inside the folder lambda
More details on my Medium Post: Discord notification using CloudWatch Alarms, SNS and AWS Lambda
- https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ConsoleAlarms.html
- https://discord.com/developers/docs/resources/channel#embed-limits
- https://docs.aws.amazon.com/lambda/latest/dg/monitoring-metrics.html
- https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm