Skip to content

NotHarshhaa/aws-billing-alert-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ AWS Billing Alert Terraform Module

AWS-billing

Welcome to the AWS Billing Alert Terraform module! This module helps you set up automatic billing alerts for your AWS account. Once configured, you'll receive notifications when your AWS charges exceed specified amounts, helping you stay on top of your costs. ๐Ÿ’ฐ


๐Ÿ› ๏ธ Prerequisites

Important

Before you begin, make sure you have the following:

  • ๐Ÿงฐ Terraform (v1.5.0 or later) installed on your local machine.
  • ๐ŸŒ An AWS account with appropriate permissions.
  • ๐Ÿ”‘ AWS CLI configured with the necessary credentials.

๐Ÿ” Understanding the AWS Services

๐ŸŒŸ AWS CloudWatch

AWS CloudWatch is a monitoring and observability service that collects and tracks metrics, collects and monitors log files, and sets alarms. This module uses CloudWatch to monitor your AWS billing and trigger an alarm when specified thresholds are exceeded.

๐Ÿ“ข AWS SNS (Simple Notification Service)

AWS SNS is a fully managed messaging service. It allows you to send notifications to multiple subscribers. In this module, SNS is used to send billing alerts via email, SMS, or other supported channels when the CloudWatch alarm is triggered.

๐Ÿงพ AWS Billing

AWS Billing provides tools to manage your AWS costs and budget. This module automates the monitoring of your AWS billing, so you're notified before your bill goes beyond your expectations.


๐Ÿš€ Latest Features & Security Improvements [2025]

โœ… Enhanced Security โ€“ Added proper SNS and SQS policies for secure communication
โœ… Fixed DLQ Integration โ€“ Dead-letter queue now properly handles failed notifications
โœ… Resource Dependencies โ€“ Proper dependency management for reliable deployment
โœ… Multiple Email Alerts โ€“ Supports multiple recipients by allowing a list of emails
โœ… Per-Service Billing Alerts โ€“ Monitors spending on individual AWS services like EC2
โœ… Enhanced CloudWatch Filters โ€“ Improved billing log monitoring for better cost visibility
โœ… OK Actions โ€“ Sends recovery notifications when charges return to normal
โœ… Better Code Organization โ€“ Separated outputs and versions for maintainability
โœ… Configuration Summary โ€“ Enhanced outputs for better monitoring and debugging


๐Ÿ“ฆ Setup Instructions

1๏ธโƒฃ Clone the Repository

  1. Open your terminal or command prompt.

  2. Navigate to the directory where you'd like to place the project:

    cd /path/to/your/directory  
  3. Clone the repository:

    git clone https://github.com/NotHarshhaa/aws-billing-alert-terraform.git  
  4. Move into the directory:

    cd aws-billing-alert-terraform  

2๏ธโƒฃ Install Terraform

Follow the steps in your system documentation to install Terraform or use the quick instructions for Amazon Linux:

sudo yum install -y yum-utils shadow-utils  
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo  
sudo yum -y install terraform  
terraform --version  

3๏ธโƒฃ Initialize Terraform

Prepare Terraform for use:

terraform init  

4๏ธโƒฃ Configure and Apply Changes

Update Configuration Variables:

Configure your billing alerts using the provided terraform.tfvars.example file:

# Copy terraform.tfvars.example to terraform.tfvars and customize
aws_region            = "us-east-1"  
alert_thresholds      = [100, 150, 200]  
currency              = "USD"  
email_endpoints       = ["your-email@example.com", "team@example.com"]  
environment_tag       = "Production"  
auto_confirm_subscription = false  
sns_topic_name        = "billing-alert"  

Key Features:

  • ๐Ÿ”’ Secure by Default โ€“ Proper IAM policies and access controls
  • ๐Ÿ“ง Multiple Recipients โ€“ Send alerts to multiple email addresses
  • ๐Ÿ”„ Reliable Delivery โ€“ DLQ handles failed notifications automatically
  • ๐Ÿ“Š Service Monitoring โ€“ Separate alerts for total and EC2-specific charges
  • โœ… Recovery Notifications โ€“ Get alerts when charges return to normal

Apply the Configuration:

terraform apply  

๐Ÿ“ Example Usage

Here's an example configuration:

module "billing_alert" {  
  source                     = "github.com/NotHarshhaa/aws-billing-alert-terraform"  
  aws_region                 = "us-west-2"  
  alert_thresholds           = [100, 150, 200]  
  email_endpoints            = ["my-email@example.com", "finance@example.com"]  
  auto_confirm_subscription  = false  
  currency                   = "USD"  
  environment_tag            = "Production"  
  sns_topic_name             = "billing-alert"  
}  

๐Ÿ“Š Module Outputs

After deployment, you'll get these useful outputs:

# SNS topic for monitoring  
output "sns_topic_arn"  

# List of all alarm names  
output "cloudwatch_alarm_names"  
output "service_alarm_names"  

# DLQ for troubleshooting  
output "sns_dlq_arn"  

# Configuration summary  
output "configuration_summary"  

๐ŸŽฏ Usage

This module is designed for simplicity and reliability:

  1. Quick Setup โ€“ Copy terraform.tfvars.example to terraform.tfvars
  2. Configure Emails โ€“ Add your email addresses to email_endpoints
  3. Set Thresholds โ€“ Adjust alert_thresholds based on your budget
  4. Deploy โ€“ Run terraform apply
  5. Monitor โ€“ Receive alerts when charges exceed your thresholds

๐Ÿ”ง Advanced Configuration

The module supports these customizations:

  • Multiple thresholds โ€“ Get alerts at different spending levels
  • Service-specific monitoring โ€“ EC2 service charges tracked separately
  • Custom regions and currencies โ€“ Deploy anywhere with local currency
  • Environment tagging โ€“ Organize resources by environment

๐Ÿ›ก๏ธ Security Features

  • Least Privilege Access โ€“ Only necessary permissions granted
  • Secure Communication โ€“ Proper SNS and SQS policies
  • Resource Isolation โ€“ Clear separation of concerns
  • No Hardcoded Secrets โ€“ All configuration via variables

๏ฟฝ Customization

Billing Thresholds

Modify the alert_thresholds in your terraform.tfvars file to configure additional thresholds:

alert_thresholds = [100, 150, 200, 250]

Email Subscription Auto-Confirmation

For testing purposes, you can enable automatic email confirmation by setting:

auto_confirm_subscription = true

Important

Use this option only in test environments with proper permissions.

Supported Variables

Variable Description Default Required
aws_region AWS region for deployment us-east-1 No
alert_thresholds Billing thresholds in USD [100, 120] No
email_endpoints Email addresses for alerts ['your-email@example.com'] Yes
currency Billing currency USD No
environment_tag Environment tag for resources Production No
auto_confirm_subscription Auto-confirm email subs false No
sns_topic_name SNS topic name billing-alert No

๏ฟฝ๐Ÿ™Œ Feedback and Contributions

Tip

We'd love to hear your thoughts! Whether it's feedback, bug reports, or pull requests, feel free to get involved. Your contributions help make this module better for everyone.

โญ Hit the Star

Important

If you find this repository helpful for learning or in practice, please hit the star button on GitHub. โญ It helps others find this resource too!

๐Ÿ‘ค Author

banner

Tip

Join Our Telegram Community || Follow me on GitHub for more DevOps content!

About

๐“๐ก๐ข๐ฌ ๐ซ๐ž๐ฉ๐จ๐ฌ๐ข๐ญ๐จ๐ซ๐ฒ ๐œ๐จ๐ง๐ญ๐š๐ข๐ง๐ฌ ๐š ๐“๐ž๐ซ๐ซ๐š๐Ÿ๐จ๐ซ๐ฆ ๐ฆ๐จ๐๐ฎ๐ฅ๐ž ๐ญ๐ก๐š๐ญ ๐ก๐ž๐ฅ๐ฉ๐ฌ ๐ฌ๐ž๐ญ ๐ฎ๐ฉ ๐€๐–๐’ ๐›๐ข๐ฅ๐ฅ๐ข๐ง๐  ๐š๐ฅ๐ž๐ซ๐ญ๐ฌ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages