sourav chakrabortyπΈ Stop wasting money on unused AWS resources β automate cleanup with Go π...
πΈ Stop wasting money on unused AWS resources β automate cleanup with Go
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.
Orphan resources are:
AWS resources that are no longer in use but still cost money
Flow:
EventBridge (Scheduler)
β
Go Program (Scanner)
β
AWS APIs (EC2)
β
Detect Orphan Resources
β
Alert / Delete
No runtime dependency β perfect for automation & Lambda
Fast execution for large AWS environments
Scan multiple regions in parallel using goroutines
Strong typing β reduces accidental deletion risks
If you're new to Go, hereβs what you need:
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
name := "AWS Cleaner"
count := 5
if err != nil {
fmt.Println("Error:", err)
}
Check:
go version
If not installed:
π https://go.dev/dl/
mkdir orphan-cleaner
cd orphan-cleaner
go mod init orphan-cleaner
Create file:
nano main.go
Paste the Orphan Cleaner code.
go mod tidy
aws configure
OR
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=xxx
export AWS_REGION=ap-south-1
go run main.go
π 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
const autoDelete = false
Keep=true
Critical=yes
Only delete resources older than 7 days.
Use Amazon SNS to:
This simple tool can:
| Feature | Go | Python |
|---|---|---|
| Deployment | Single binary | Runtime needed |
| Performance | Fast | Slower |
| Concurrency | Native | Limited |
| Lambda cold start | Low | Higher |
Youβve built a production-relevant AWS automation tool using Go.
This isnβt just a demo β itβs something:
Want to take it further?
βUnused cloud resources are silent money leaks β automation is the only scalable fix.β