Skip to content
Snippets Groups Projects
Commit a607e421 authored by Edouard DE BRYE's avatar Edouard DE BRYE
Browse files

Merge branch 'feature/add-alarm-for-lambda-throttles' into 'master'

Added metric alarms for lambda errors and throttling

See merge request edebrye/cloud-monitor!9
parents 028c1c48 7634742a
No related branches found
No related tags found
No related merge requests found
......@@ -88,28 +88,10 @@ resource "aws_api_gateway_stage" "main" {
tags = local.common_tags
}
resource "aws_api_gateway_account" "apigw" {
cloudwatch_role_arn = aws_iam_role.cloudwatch.arn
}
resource "aws_iam_role" "cloudwatch" {
name = "${local.prefix}-api_gateway_cloudwatch_global"
assume_role_policy = file("./templates/api-gateway/assume-role-policy.json")
}
resource "aws_iam_role_policy" "cloudwatch" {
name = "${local.prefix}-default"
role = aws_iam_role.cloudwatch.id
policy = file("./templates/api-gateway/cloud-watch-policy.json")
}
resource "aws_api_gateway_method_settings" "general_settings" {
rest_api_id = aws_api_gateway_rest_api.main.id
stage_name = aws_api_gateway_stage.main.stage_name
method_path = "*/*"
depends_on = [aws_api_gateway_account.apigw]
settings {
# Enable CloudWatch logging and metrics
......
data "aws_sns_topic" "cloudmon" {
name = "edebrye-cloudmon"
}
resource "aws_cloudwatch_metric_alarm" "lambda_throttles_alarm" {
for_each = local.lambdas
alarm_name = "${local.prefix}-${each.key}-throttle-alarm"
alarm_description = "Alert staff when throttles occurs on cloud-monitor project's lambdas."
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
period = 300
threshold = 1
namespace = "AWS/Lambda"
statistic = "Sum"
alarm_actions = [data.aws_sns_topic.cloudmon.arn]
ok_actions = [data.aws_sns_topic.cloudmon.arn]
metric_name = "Throttles"
dimensions = {
FunctionName = aws_lambda_function.crud[each.key].function_name
}
tags = local.common_tags
}
resource "aws_cloudwatch_metric_alarm" "lambda_error_alarm" {
for_each = local.lambdas
alarm_name = "${local.prefix}-${each.key}-error-alarm"
alarm_description = "Alert staff when errors occurs on cloud-monitor project's lambdas."
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
period = 300
threshold = 1
namespace = "AWS/Lambda"
statistic = "Sum"
alarm_actions = [data.aws_sns_topic.cloudmon.arn]
ok_actions = [data.aws_sns_topic.cloudmon.arn]
metric_name = "Errors"
dimensions = {
FunctionName = aws_lambda_function.crud[each.key].function_name
}
tags = local.common_tags
}
\ No newline at end of file
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "apigateway.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
\ No newline at end of file
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
"logs:GetLogEvents",
"logs:FilterLogEvents"
],
"Resource": "*"
}
]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment