This module implements a lambda that monitors AWS reserved instances every 24 hours across multiple services and alerts when they're about to expire. The Lambda prevents unexpected cost increases by alerting teams when reserved instances are nearing expiration, allowing time to renew or adjust resources.
-
Collect Reservation Data:
- Queries across multiple AWS services (RDS, RedShift, EC2)
- Filters for active reservations only
- Standardizes reservation information into a common format
-
Check Expiration Timeframes:
- Calculates days remaining until reservation expiry
- Flags reservations with critical timeframes (7 days and 1 day)
- Assigns priority levels (P2 for 7 days, P1 for 1 day)
-
Send Notifications:
- Determines notification method based on endpoint configuration
- For SNS: Sends formatted alerts to SNS topics
- For SQS: Creates structured JSON messages for queue processing
-
Handle Errors:
- Captures exceptions with full traceback information
- Creates formatted error messages for logging
- Raises exceptions for Lambda monitoring
Run pre-commit install
to install any guardrails implemented using pre-commit.
See pre-commit installation on how to install pre-commit.
...
To use this module ...
module "reservation_alerter" {
source = "github.com/wearetechnative/terraform-aws-module-instance-reservation-alerter.git?ref=f7856e6288ac2cd41362bc085cf2a7fdeb683a99"
sqs_dlq_arn = sqs.dlq.arn
kms_key_arn = kms.default_key.arn
client_name = "ClientName"
account_name = "Production"
notification_endpoints = ["https://sqs.eu-central-1.amazonaws.com/123455677/sqs_name", aws_sns_topic.observability.arn]
}