AWS Lambda functions for automating routine cloud operations including EBS volume backups, RDS cross-region disaster recovery, and snapshot lifecycle management.
| Function | Description |
|---|---|
| backupvolume.py | Automated EBS volume snapshots with tag-based selection |
| prunevolume.py | Snapshot retention cleanup to manage storage costs |
| snapshot_creation.py | RDS automated snapshot creation |
| copy_snapshot.py | Cross-region RDS snapshot replication for DR |
| resotring_snapshot.py | RDS instance restoration from snapshot |
| pruning_snapshot.py | RDS snapshot retention and lifecycle management |
CloudWatch Events (Schedule)
│
▼
AWS Lambda ──► EBS Snapshots / RDS Snapshots
│
▼
SNS Notifications (Optional)
.
├── lambdafunctions/
│ ├── Automating Backups using AWS Lambda/
│ │ ├── backupvolume.py # Create EBS snapshots
│ │ └── prunevolume.py # Clean up old snapshots
│ └── RDS failover/
│ ├── snapshot_creation.py # Create RDS snapshots
│ ├── copy_snapshot.py # Cross-region copy
│ ├── resotring_snapshot.py # Restore from snapshot
│ └── pruning_snapshot.py # Retention cleanup
├── iam/
│ ├── iam_role_ebs.json # IAM role for EBS Lambda
│ └── iam_rds.json # IAM role for RDS Lambda
└── images/ # Architecture diagrams
iam/:
aws iam create-role --role-name LambdaEBSBackup \
--assume-role-policy-document file://iam/iam_role_ebs.json
cd "lambdafunctions/Automating Backups using AWS Lambda"
zip backupvolume.zip backupvolume.py
aws lambda create-function \
--function-name EBSBackup \
--runtime python3.9 \
--handler backupvolume.lambda_handler \
--role arn:aws:iam::YOUR_ACCOUNT:role/LambdaEBSBackup \
--zip-file fileb://backupvolume.zip
aws events put-rule --name DailyEBSBackup \
--schedule-expression "rate(1 day)"
Backup: true to include them in automated snapshotsRETENTION_DAYS environment variable to control snapshot cleanupPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Hammad Haqqani - DevOps Architect & Cloud Engineer
If you find this useful, consider buying me a coffee!