Skip to content

Commit

Permalink
make spend alarm sns + pinpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Jun 10, 2024
1 parent f7ebfd9 commit bc12e02
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 21 deletions.
85 changes: 67 additions & 18 deletions aws/pinpoint_to_sqs_sms_callbacks/cloudwatch_alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,84 @@ resource "aws_cloudwatch_metric_alarm" "lambda-image-pinpoint-delivery-receipts-
}
}

resource "aws_cloudwatch_metric_alarm" "pinpoint-spending-warning" {
resource "aws_cloudwatch_metric_alarm" "total-sms-spending-warning" {
count = var.cloudwatch_enabled ? 1 : 0
alarm_name = "pinpoint-spending-warning"
alarm_description = "Pinpoint spending reached 80% of limit this month"
alarm_name = "total-sms-spending-warning"
alarm_description = "SMS spending reached 80% of limit this month"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "TextMessageMonthlySpend"
namespace = "AWS/SMSVoice"
period = "300"
statistic = "Maximum"
threshold = 0.8 * var.pinpoint_monthly_spend_limit
threshold = 0.8 * var.sms_monthly_spend_limit
treat_missing_data = "notBreaching"
alarm_actions = [var.sns_alert_warning_arn]

metric_query {
id = "total_spend"
expression = "sns_spend + pinpoint_spend"
label = "Total SMS Monthly Spend"
return_data = "true"
}

metric_query {
id = "sns_spend"
metric {
metric_name = "SMSMonthToDateSpentUSD"
namespace = "AWS/SNS"
period = 300
stat = "Maximum"
unit = "Count"
}
}

metric_query {
id = "pinpoint_spend"
metric {
metric_name = "TextMessageMonthlySpend"
namespace = "AWS/SMSVoice"
period = 300
stat = "Maximum"
unit = "Count"
}
}
}

resource "aws_cloudwatch_metric_alarm" "pinpoint-spending-critical" {
resource "aws_cloudwatch_metric_alarm" "total-sms-spending-critical" {
count = var.cloudwatch_enabled ? 1 : 0
alarm_name = "pinpoint-spending-critical"
alarm_description = "Pinpoint spending reached 90% of limit this month"
alarm_name = "total-sms-spending-critical"
alarm_description = "SMS spending reached 90% of limit this month"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "TextMessageMonthlySpend"
namespace = "AWS/SMSVoice"
period = "300"
statistic = "Maximum"
threshold = 0.9 * var.pinpoint_monthly_spend_limit # pinpoint limit is the same as sns
threshold = 0.9 * var.sms_monthly_spend_limit
treat_missing_data = "notBreaching"
alarm_actions = [var.sns_alert_critical_arn]
ok_actions = [var.sns_alert_ok_arn]
alarm_actions = [var.sns_alert_warning_arn]

metric_query {
id = "total_spend"
expression = "sns_spend + pinpoint_spend"
label = "Total SMS Monthly Spend"
return_data = "true"
}

metric_query {
id = "sns_spend"
metric {
metric_name = "SMSMonthToDateSpentUSD"
namespace = "AWS/SNS"
period = 300
stat = "Maximum"
unit = "Count"
}
}

metric_query {
id = "pinpoint_spend"
metric {
metric_name = "TextMessageMonthlySpend"
namespace = "AWS/SMSVoice"
period = 300
stat = "Maximum"
unit = "Count"
}
}
}

resource "aws_cloudwatch_metric_alarm" "pinpoint-sms-success-rate-warning" {
Expand Down
4 changes: 2 additions & 2 deletions aws/pinpoint_to_sqs_sms_callbacks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ variable "pinpoint_to_sqs_sms_callbacks_ecr_arn" {
description = "The ARN of the ECR repository for the pinpoint_to_sqs_sms_callbacks image"
}

variable "pinpoint_monthly_spend_limit" {
variable "sms_monthly_spend_limit" {
type = number
description = "The monthly spending limit for Amazon Pinpoint"
description = "The total monthly spending limit for SMS (SNS plus Pinpoint)"
}

variable "force_delete_ecr" {
Expand Down
2 changes: 1 addition & 1 deletion env/dev/pinpoint_to_sqs_sms_callbacks/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inputs = {
sqs_deliver_receipts_queue_arn = dependency.common.outputs.sqs_deliver_receipts_queue_arn
pinpoint_to_sqs_sms_callbacks_ecr_repository_url = dependency.ecr.outputs.pinpoint_to_sqs_sms_callbacks_ecr_repository_url
pinpoint_to_sqs_sms_callbacks_ecr_arn = dependency.ecr.outputs.pinpoint_to_sqs_sms_callbacks_ecr_arn
pinpoint_monthly_spend_limit = dependency.common.outputs.sns_monthly_spend_limit
sms_monthly_spend_limit = dependency.common.outputs.sns_monthly_spend_limit
}

terraform {
Expand Down

0 comments on commit bc12e02

Please sign in to comment.