Listen to this Post

Easily Improve Operations with Amazon EventBridge and AWS Lambda: Automate Reporting of Aged RDS Snapshots
(Source: Medium )
You Should Know:
Automating cleanup tasks in AWS is critical for cost optimization and operational efficiency. Below are practical steps and commands to implement automated RDS snapshot cleanup using AWS EventBridge and Lambda.
Step 1: Set Up AWS Lambda Function
Create a Python Lambda function to identify and delete old RDS snapshots:
import boto3
from datetime import datetime, timedelta
def lambda_handler(event, context):
rds = boto3.client('rds')
snapshots = rds.describe_db_snapshots()['DBSnapshots']
retention_days = 30 Adjust as needed
cutoff_time = datetime.now() - timedelta(days=retention_days)
for snapshot in snapshots:
if snapshot['SnapshotCreateTime'] < cutoff_time:
print(f"Deleting old snapshot: {snapshot['DBSnapshotIdentifier']}")
rds.delete_db_snapshot(DBSnapshotIdentifier=snapshot['DBSnapshotIdentifier'])
return {"status": "Snapshot cleanup completed"}
Step 2: Configure Amazon EventBridge Rule
Schedule the Lambda function to run periodically:
1. Open Amazon EventBridge → Create Rule.
- Set a Schedule (e.g., `rate(7 days)` for weekly cleanup).
- Select Lambda as the target and attach the function.
Step 3: Apply Terraform for Infrastructure as Code (IaC)
Automate deployment using Terraform:
resource "aws_lambda_function" "rds_cleanup" {
filename = "lambda_function.zip"
function_name = "rds_snapshot_cleanup"
role = aws_iam_role.lambda_exec.arn
handler = "lambda_function.lambda_handler"
runtime = "python3.8"
}
resource "aws_cloudwatch_event_rule" "weekly_cleanup" {
name = "weekly-rds-cleanup"
schedule_expression = "rate(7 days)"
}
resource "aws_cloudwatch_event_target" "trigger_lambda" {
rule = aws_cloudwatch_event_rule.weekly_cleanup.name
target_id = "lambda_trigger"
arn = aws_lambda_function.rds_cleanup.arn
}
Step 4: Verify with AWS CLI
Check snapshots before and after cleanup:
aws rds describe-db-snapshots --query 'DBSnapshots[].[DBSnapshotIdentifier,SnapshotCreateTime]' --output table
What Undercode Say:
Automating AWS RDS snapshots prevents cost overruns and ensures compliance. Key takeaways:
– Use Lambda + EventBridge for scheduled cleanup.
– Terraform ensures repeatable deployments.
– AWS CLI helps verify snapshots.
– Always test in a non-production environment first.
Prediction:
As cloud costs rise, more organizations will adopt automated cleanup workflows, integrating AI-driven cost optimization tools.
Expected Output:
- Old RDS snapshots deleted automatically.
- Reduced AWS storage costs.
- Logs in CloudWatch for audit purposes.
References:
Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


