AWS Cost Monitoring & Budget Alert Automation

This project automates AWS cost monitoring and alerting using a serverless architecture powered by:

  • AWS Budgets (for tracking spending thresholds)

  • AWS Lambda (for processing alerts and generating daily reports)

  • Amazon SNS (for email alerts)

  • EventBridge (for scheduled daily reports)

  • Slack Webhooks (for real-time notifications)

  • Terraform (for full Infrastructure as Code) GitHub Link Repo


What It Does

✅ Sends a daily AWS cost summary to Slack via a configured Webhook URL
✅ Triggers email alerts via SNS when the AWS monthly budget threshold is exceeded
✅ Uses a Lambda function to process and format budget alerts before forwarding to subscribers


Technologies Used

  • AWS Lambda

  • AWS SNS

  • AWS Budgets

  • EventBridge (CloudWatch Scheduler)

  • Slack Webhook

  • Python 3.9

  • Terraform

Setup Instructions

1. Clone the Repository

git clone https://github.com/yourusername/aws-cost-monitoring.git
cd aws-cost-monitoring

2. Generate a Slack Webhook URL

To receive cost alerts in Slack:

  1. Go to your Slack workspace

  1. Navigate to Apps and search for Incoming Webhooks

  2. Click Add to Slack

  1. Select a channel where messages should appear

  1. Click Add Incoming Webhooks integration

  2. Copy the Webhook URL provided (e.g., https://hooks.slack.com/services/...)

3. Provide the values of the following to variable.tf

slack_webhook_url     = "https://hooks.slack.com/services/..."
alert_email_address   = "your@email.com"

4. Deploy the Infrastructure

cd infra
terraform init
terraform plan
terraform apply --auto-approve

📬 Check your inbox to verify the SNS email subscription!

5. Configure the AWS Budget Manually

Go to the AWS Console → Budgets → Create a monthly cost budget manually with the following:

  • Budget type: Cost

  • Threshold: 80% or any value you prefer

  • Budget Alert: SNS Topic created by Terraform (e.g., aws-budget-alerts)

6. (Optional) Terraform Destroy

To remove the infrastructure when you're done testing:

terraform destroy

Troubleshooting: Overcoming Terraform & AWS SNS Issues

While deploying the cost management alert system using Terraform and AWS, I ran into a few stumbling blocks. Here’s how I worked through them and got everything running smoothly:

Problem 1: SNS Topic and Email Subscription Not Triggering

After running terraform apply, I expected my SNS topic and email subscription to be automatically created and verified. However, nothing appeared in my AWS SNS console, and I did not receive a confirmation email at the email address I provided(@proton.me).

Solution:

  • I manually went to the AWS Console → SNS and created the topic and email subscription myself.

  • I noticed that Proton Mail sometimes delays or blocks AWS confirmation emails, so I switched to Gmail: @gmail.com.

  • After doing that, I received the email and confirmed the subscription successfully.

Problem 2: Terraform Didn't Detect My Manual Resources

Because I created the SNS topic and subscription manually, Terraform didn't recognise them in its state. This can cause inconsistencies.

Solution:

To bring the manually created resources under Terraform management, I used the terraform import command:

bashCopyEditterraform import aws_sns_topic.budget_alert arn:aws:sns:us-east-1:123456789012:budget_alert_topic

This told Terraform: “Hey, this resource already exists — manage it from now on.”

Problem 3: Lambda Notification Not Triggering

Even after the SNS and subscription were working, my Lambda function didn’t seem to trigger alerts.

Solution:

  • I double-checked the SNS topic ARN being used in the Lambda code.

  • Made sure the Lambda had publish permissions to that topic.

  • Then manually tested the Lambda from the console to simulate a budget alert.

Lessons Learned

  • Email deliverability matters — always test with a known-compatible provider like Gmail.

  • Terraform isn't magic — if you go manual, you must bring resources back into state with import.

  • SNS + Lambda + Slack/Email integrations can break silently. Always test each piece in isolation.

0
Subscribe to my newsletter

Read articles from Chigozie Ozoemena directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chigozie Ozoemena
Chigozie Ozoemena

Hi there! 👋 I'm Daniel Ozoemena, a passionate Cloud Solution Architect and DevOps Engineer dedicated to building scalable, secure, and innovative cloud solutions. With hands-on experience in Azure, AWS, and Google Cloud Platform, I specialize in deploying infrastructure as code, automating workflows, and optimizing system reliability. Driven by a love for problem-solving, I constantly explore new technologies and best practices to deliver impactful results. Beyond the cloud, I enjoy mentoring, blogging about tech insights, and contributing to open-source projects. When I'm not automating deployments or creating secure virtual networks, you can find me playing chess, learning about AI, or brainstorming solutions to real-world challenges. Let’s connect and grow together on this tech journey! 🚀