Skip to content

Terraform project to automate RDS backups and monitor database health using Lambda, CloudWatch, SNS, and EventBridge. Logs snapshot metadata to S3.

Notifications You must be signed in to change notification settings

jbrewinthecloud/rds-backup-monitoring

Repository files navigation

🛡️ Automated Backup and Monitoring for Amazon RDS (Terraform)

This project automates the process of creating daily manual snapshots for an Amazon RDS instance and monitors its health using CloudWatch alarms. All infrastructure is provisioned using Terraform.


📌 Problem Statement

Ensure data durability and availability by:

  • Automatically backing up RDS databases daily
  • Monitoring critical metrics like CPU usage
  • Alerting via email when thresholds are breached

🧰 AWS Services Used

  • Amazon RDS – Free-tier MySQL instance with automated and manual backups
  • Amazon S3 – Stores snapshot metadata logs
  • AWS Lambda – Automates manual snapshot creation and log storage
  • Amazon EventBridge – Triggers Lambda on a daily schedule
  • Amazon CloudWatch – Monitors RDS health metrics
  • Amazon SNS – Sends email notifications
  • Amazon SES (optional) – For branded/custom email notifications

🗂️ Project Structure

rds-backup-monitoring/ ├── main.tf # Main infrastructure components ├── variables.tf # Input variables ├── outputs.tf # Output values ├── iam.tf # IAM roles and policies for Lambda ├── lambda/ │ ├── snapshot_lambda.py # Python Lambda code for RDS snapshot and logging │ └── snapshot_lambda.zip


⚙️ Features

  • ✅ Daily RDS snapshot triggered by EventBridge
  • ✅ Logs snapshot metadata to S3
  • ✅ CloudWatch alarm for high CPU usage
  • ✅ SNS email alert to notify admins
  • ✅ All infrastructure managed via Terraform

🚀 Deployment Steps

  1. Clone the Repo
    git clone https://github.com/yourusername/rds-backup-monitoring.git
    cd rds-backup-monitoring
  2. Configure AWS Credentials aws configure
  3. Zip the Lambda Function cd lambda zip snapshot_lambda.zip snapshot_lambda.py cd ..
  4. Initialize Terraform terraform init
  5. Apply Infrastructure terraform plan -out=tfplan terraform apply tfplan
  6. Confirm Email Subscription Check your inbox for an SNS confirmation email Click "Confirm Subscription"

🧪 Optional Enhancements Add snapshot retention logic (e.g., delete after 7 days) Include multi-metric CloudWatch dashboards Integrate with SES for rich HTML email alerts Trigger snapshot on-demand via API Gateway

📬 Pro Tip: Use Crosslinks This repo shows the automated Terraform version of my blog post. Want to see the manual setup step-by-step? 👉 Read the full guide on Medium

🧑‍💻 Author Jermaine Brewer Founder of JB Consulting | Cloud Engineer @ JBrewInTheCloud.com

Let’s connect on LinkedIn - Jermaine Brewer

About

Terraform project to automate RDS backups and monitor database health using Lambda, CloudWatch, SNS, and EventBridge. Logs snapshot metadata to S3.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published