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
- AWS account with Lambda, EBS, RDS, CloudWatch, and IAM permissions
- Python 3.9+ runtime (AWS Lambda)
- AWS CLI configured for deployment
-
Create the IAM role using the policies in
iam/:aws iam create-role --role-name LambdaEBSBackup \ --assume-role-policy-document file://iam/iam_role_ebs.json
-
Deploy a Lambda function (example: EBS backup):
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
-
Schedule with CloudWatch Events:
aws events put-rule --name DailyEBSBackup \ --schedule-expression "rate(1 day)"
- EBS Backup: Tag your volumes with
Backup: trueto include them in automated snapshots - RDS DR: Configure the source and destination regions in the Lambda environment variables
- Retention: Set
RETENTION_DAYSenvironment variable to control snapshot cleanup
Pull 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
- Website: hammadhaqqani.com
- LinkedIn: linkedin.com/in/haqqani
- Email: phaqqani@gmail.com
If you find this useful, consider buying me a coffee!