-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from co-cddo/lambda-monitoring
Add basic lambda monitoring
- Loading branch information
Showing
8 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.0.1 | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Lambda Monitoring Module | ||
|
||
This Terraform module, **lambda-monitoring**, is designed to set up AWS monitoring and reporting for a lambda mfunction. It includes functionality for lambda and CloudWatch alarms. | ||
|
||
## Features | ||
|
||
- **SNS Alerts**: A single SNS topic that sends notifications to a specified email when health checks fail. | ||
- **CloudWatch Alarms**: Monitors health check statuses and triggers alerts via SNS. | ||
|
||
## Usage | ||
|
||
### Example Usage | ||
|
||
```hcl | ||
locals { | ||
lambda_name = "lambda-dev" | ||
} | ||
module "lambda_monitoring" { | ||
source = "[email protected]/co-cddo/gc3-terraform-module-monitoring.git//lambda-monitoring:lambda-monitoring?ref=v1.0.0" | ||
lambda_name = local.lambda_name | ||
statistic = "Sum" | ||
alarm_description = "Alarm for Lambda function errors exceeding threshold" | ||
alarm_name = "${local.lambda_name}-Lambda-Alarm" | ||
topic_subscription = "[email protected]"" | ||
} | ||
output "cloudwatch_alarm_arn" { | ||
value = module.lambda_monitoring."[email protected]" | ||
} | ||
``` | ||
|
||
### Required Variables | ||
|
||
- **`lambda_name`** (string): Required : A unique name for the alarm. | ||
- **`alarm_name`** (string): Required: The descriptive name for the alarm. This name must be unique within the user's AWS account. Automatically appended with "-Error-Alarm" | ||
- **`metric_name`** (string): Required : The name for the alarm's associated metric. | ||
|
||
### Optional Variables | ||
|
||
- **`comparison_operator`** (string): Default **GreaterThanOrEqualToThreshold** : The arithmetic operation to use when comparing the specified Statistic and Threshold. | ||
- **`evaluation_periods`** (number): Default **1** : The number of periods over which data is compared to the specified threshold. | ||
- **`namespace`** (string): Default **AWS/Lambda** : The namespace for the alarm's associated metric. | ||
- **`period`** (string): Default **3** : The period in seconds over which the specified statistic is applied. Valid values are 10, 30, or any multiple of 60 | ||
- **`statistic`** (string): Default **Sum** : The statistic to apply to the alarm's associated metric. Either of the following is supported: SampleCount, Average, Sum, Minimum, Maximum | ||
- **`threshold`** (number): Default **3** : The value against which the specified statistic is compared. This parameter is required for alarms based on static thresholds. | ||
- **`insufficient_data_actions`** (list(string)): Default **[]** : (Optional) The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state from any other state. | ||
- **`treat_missing_data`** (string): (Optional): Default **missing** : Sets how this alarm is to handle missing data points. | ||
- **`alarm_description`** (string): (Optional): Default **Alarm for Lambda function errors exceeding threshold** : | ||
|
||
- **`protocol`** (string): Default **email** : Protocol to use. | ||
- **`topic_subscription`** (string): Required : Endpoint to send data to; for email this is the email address. | ||
|
||
### Outputs | ||
|
||
- **`cloudwatch_alarm_arn`** : arn of the aws cloudwatch alarm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
resource "aws_cloudwatch_metric_alarm" "lambda_error_alarm" { | ||
alarm_name = var.alarm_name | ||
comparison_operator = var.comparison_operator | ||
evaluation_periods = var.evaluation_periods | ||
metric_name = var.metric_name | ||
namespace = var.namespace | ||
period = var.period | ||
statistic = var.statistic | ||
threshold = var.threshold | ||
alarm_actions = [aws_sns_topic.lambda_alarm_topic.arn] | ||
ok_actions = [aws_sns_topic.lambda_alarm_topic.arn] | ||
insufficient_data_actions = var.insufficient_data_actions | ||
treat_missing_data = var.treat_missing_data | ||
alarm_description = var.alarm_description | ||
dimensions = { | ||
FunctionName = var.lambda_name | ||
} | ||
} | ||
|
||
resource "aws_sns_topic" "lambda_alarm_topic" { | ||
name = var.alarm_name | ||
} | ||
resource "aws_sns_topic_subscription" "lambda_alarm_subscription" { | ||
topic_arn = aws_sns_topic.lambda_alarm_topic.arn | ||
protocol = var.protocol | ||
endpoint = var.topic_subscription | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Lambda Monitoring Module | ||
|
||
This Terraform module, **lambda-monitoring**, is designed to set up AWS monitoring and reporting for a lambda mfunction. It includes functionality for lambda and CloudWatch alarms. | ||
|
||
## Features | ||
|
||
- **SNS Alerts**: A single SNS topic that sends notifications to a specified email when health checks fail. | ||
- **CloudWatch Alarms**: Monitors health check statuses and triggers alerts via SNS. | ||
|
||
## Usage | ||
|
||
### Example Usage | ||
|
||
```hcl | ||
locals { | ||
lambda_name = "lambda-dev" | ||
} | ||
module "lambda_monitoring" { | ||
source = "[email protected]/co-cddo/gc3-terraform-module-monitoring.git//lambda-monitoring:lambda-monitoring?ref=v1.0.0" | ||
lambda_name = local.lambda_name | ||
statistic = "Sum" | ||
alarm_description = "Alarm for Lambda function errors exceeding threshold" | ||
alarm_name = "${local.lambda_name}-Lambda-Alarm" | ||
topic_subscription = "[email protected]"" | ||
} | ||
output "cloudwatch_alarm_arn" { | ||
value = module.lambda_monitoring."[email protected]" | ||
} | ||
``` | ||
|
||
### Required Variables | ||
|
||
- **`lambda_name`** (string): Required : A unique name for the alarm. | ||
- **`alarm_name`** (string): Required: The descriptive name for the alarm. This name must be unique within the user's AWS account. | ||
- **`metric_name`** (string): Required : The name for the alarm's associated metric. | ||
- **`topic_subscription`** (string): Required : Endpoint to send data to. For email this is the email address. | ||
|
||
### Optional Variables | ||
|
||
- **`comparison_operator`** (string): Def **GreaterThanOrEqualToThreshold** : The operation to use when comparing the specified Statistic and Threshold. | ||
- **`evaluation_periods`** (number): Def **1** : The number of periods over which data is compared. | ||
- **`namespace`** (string): Def **AWS/Lambda** : The namespace for the alarm's associated metric. | ||
- **`period`** (string): Def **30** : The period in seconds over which the specified statistic is applied. 10, 30, or any multiple of 60 | ||
- **`statistic`** (string): Def **Sum** : The statistic to apply to the alarm's associated metric. i.e. SampleCount, Average, Sum, Minimum, Maximum | ||
- **`threshold`** (number): Def **3** : The value against which the specified statistic is compared. | ||
- **`insufficient_data_actions`** (list(string)): Def **[]** : (Optional) The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state. | ||
- **`treat_missing_data`** (string): (Optional): Def **missing** : Sets how this alarm is to handle missing data points. | ||
- **`alarm_description`** (string): (Optional): Def **Alarm for Lambda function errors exceeding threshold** : | ||
|
||
- **`protocol`** (string): Def **email** : Protocol to use. | ||
|
||
### Outputs | ||
|
||
- **`cloudwatch_alarm_arn`** : arn of the aws cloudwatch alarm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "cloudwatch_alarm_arn" { | ||
description = "The ARN of the CloudWatch alarm" | ||
value = aws_cloudwatch_metric_alarm.lambda_error_alarm.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
variable "lambda_name" { | ||
type = string | ||
} | ||
variable "alarm_name" { | ||
type = string | ||
} | ||
variable "comparison_operator" { | ||
type = string | ||
default = "GreaterThanOrEqualToThreshold" | ||
} | ||
variable "evaluation_periods" { | ||
type = number | ||
default = 1 | ||
} | ||
variable "metric_name" { | ||
type = string | ||
} | ||
variable "namespace" { | ||
type = string | ||
default = "AWS/Lambda" | ||
} | ||
variable "period" { | ||
type = number | ||
default = 300 | ||
} | ||
variable "statistic" { | ||
type = string | ||
default = "Sum" | ||
} | ||
variable "threshold" { | ||
type = number | ||
default = 3 | ||
} | ||
variable "insufficient_data_actions" { | ||
type = list(string) | ||
default = [] | ||
} | ||
variable "treat_missing_data" { | ||
type = string | ||
default = "notBreaching" | ||
} | ||
variable "alarm_description" { | ||
type = string | ||
default = "Alarm for Lambda function errors exceeding threshold" | ||
} | ||
|
||
variable "protocol" { | ||
type = string | ||
default = "email" | ||
} | ||
variable "topic_subscription" { | ||
type = string | ||
default = "lambda-error-notifications" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# Release Notes | ||
|
||
## v1.2.0 | ||
- Added lambda monitoring module | ||
|
||
## v1.0.1 | ||
- Added multiple endpoint support | ||
|
||
## v1.0.0 | ||
- Module created | ||
- Module created |