How I Slashed My AWS Bill to $0 While Securing a 46GB Backup (In 1 Command) 🚀
Source: Dev.to
Introduction
Managing cloud infrastructure often feels like a balancing act between utility and cost. When I needed to shut down an entire AWS account while preserving a 46 GB backup, doing it manually via the AWS Console would have left hidden resources and lingering charges. This guide shows how I automated the discovery, backup, and cleanup steps into a single‑command workflow.
Mapping Resources
Before backing up, I had to know exactly what was running. A quick glance at the EC2 dashboard isn’t enough, so I used scripts to crawl the account and map every dependency.
Inspecting Lambda Environment Variables
Lambda environment variables frequently contain hidden RDS connection strings, MongoDB URIs, or API keys that aren’t visible in the service‑specific dashboards. By extracting these variables I ensured that all data sources were identified, not just the code.
Backup Commands
With the resource map in hand, the terminal took over. Below are the core commands I used for each service.
S3 Buckets
aws s3 sync s3://my-bucket-name ./backup/s3/my-bucket-name
aws s3 sync copies only new or changed files, making it efficient for large buckets.
Lambda Functions
# Get the function details
aws lambda get-function --function-name MyFunction
Note: Look for the Code.Location URL in the JSON response—that’s the temporary signed URL you can use to download the ZIP file.
Relational Databases
pg_dump -h [endpoint] -U [user] -d [dbname] -f backup.sql
I bypassed snapshots and exported raw .sql files directly with pg_dump (PostgreSQL) or mysqldump (MySQL).
NoSQL (DynamoDB)
aws dynamodb scan --table-name MyTable --output json > MyTable.json
A full table scan exports the entire dataset into a portable JSON format.
Cleanup: Eliminating Silent Cost Killers
After verifying the 46 GB backup locally, I ran a cleanup script to terminate resources that continue to incur charges.
# EC2 instances
aws ec2 terminate-instances --instance-ids i-12345...
# Load balancers
aws elbv2 delete-load-balancer --load-balancer-arn ...
# Elastic IPs (often overlooked)
aws ec2 release-address --allocation-id eipalloc-...
# RDS instances (skip final snapshot to avoid storage costs)
aws rclone delete-db-instance --db-instance-identifier my-db --skip-final-snapshot
Redundancy: Storing Backup Off‑AWS
A backup isn’t complete until it lives in at least two places. I synced the entire local backup/ folder to Google Drive using rclone, providing geo‑redundancy outside the AWS ecosystem.
rclone sync ./backup/ remote:backup-folder
Conclusion
By automating the discovery, extraction, and cleanup phases, I eliminated human error and ensured that “turning off the lights” left no expensive bulbs burning. The result was a documented, multi‑location backup and a $0 AWS bill.
How do you handle infrastructure decommissioning? Share your approach in the comments!