πΈ Stop wasting money on unused AWS resources β automate cleanup with Go
π Introduction
Cloud environments grow fast⦠and so do unused resources.
Unattached EBS volumes, unused Elastic IPs β they sit quietly and increase your AWS bill every month.
In this tutorial, youβll build a real-world Orphan Resource Cleaner using Go and the AWS SDK for Go v2.
π§ What Are Orphan Resources?
Orphan resources are:
AWS resources that are no longer in use but still cost money
Examples:
- πͺ« Unattached EBS volumes
- π Unassociated Elastic IPs
πΌοΈ Architecture Overview
Flow:
EventBridge (Scheduler)
β
Go Program (Scanner)
β
AWS APIs (EC2)
β
Detect Orphan Resources
β
Alert / Delete
β‘ Why Use Go for This?
π’ Single Binary Deployment
No runtime dependency β perfect for automation & Lambda
β‘ High Performance
Fast execution for large AWS environments
π§΅ Built-in Concurrency
Scan multiple regions in parallel using goroutines
π Safer Automation
Strong typing β reduces accidental deletion risks
π’ Go Basics (Quick Primer)
If you're new to Go, hereβs what you need:
Hello World
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
Variables
name := "AWS Cleaner"
count := 5
Error Handling
if err != nil {
fmt.Println("Error:", err)
}
π οΈ Step-by-Step Setup
1οΈβ£ Install Go
Check:
go version
If not installed:
π https://go.dev/dl/
2οΈβ£ Create Project
mkdir orphan-cleaner
cd orphan-cleaner
3οΈβ£ Initialize Module
go mod init orphan-cleaner
4οΈβ£ Add Code
Create file:
nano main.go
Paste the Orphan Cleaner code.
5οΈβ£ Install Dependencies
go mod tidy
6οΈβ£ Configure AWS Credentials
aws configure
OR
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=xxx
export AWS_REGION=ap-south-1
7οΈβ£ Run the Program
go run main.go
πΌοΈ Example Output
π Discovering regions...
π Scanning region: ap-south-1
π [ap-south-1] Orphan Elastic IP: 13.xxx.xxx.xxx
π Scanning region: us-east-1
π [us-east-1] Orphan Elastic IP: 100.23.233.31
π Summary Report
-------------------------
πͺ« Total Orphan EBS Volumes: 2
π Total Orphan Elastic IPs: 3
β οΈ Safety First
π Always Start with Dry Run
const autoDelete = false
π·οΈ Use Tags to Protect Resources
Keep=true
Critical=yes
β³ Add Grace Period
Only delete resources older than 7 days.
π Add Alerts (Optional)
Use Amazon SNS to:
- Send email alerts
- Notify before deletion
- Integrate with Slack
π₯ Real-World Impact
This simple tool can:
- Save real money π°
- Improve AWS hygiene
- Reduce attack surface
π€ Why Not Python?
| Feature | Go | Python |
|---|---|---|
| Deployment | Single binary | Runtime needed |
| Performance | Fast | Slower |
| Concurrency | Native | Limited |
| Lambda cold start | Low | Higher |
π― Conclusion
Youβve built a production-relevant AWS automation tool using Go.
This isnβt just a demo β itβs something:
- DevOps teams use daily
- FinOps teams rely on
- Companies build internally
π Next Steps
Want to take it further?
- π Add SNS alerts
- β‘ Add parallel scanning
- π Multi-account support
- βοΈ Deploy as Lambda
π‘ Final Thought
βUnused cloud resources are silent money leaks β automation is the only scalable fix.β

Top comments (0)