This project is for developing a solution for scheduling AMI and EBS backups using AWS Lambda. Scheduling is done using CloudWatch Events. Time shown in the diagram is just indicative. Schedule AmiBackup and EbsBackup hourly and retention functions weekly to reduce total Lambda execution time.
AWS is not providing any option to automate AMI or EBS snapshot. So we have to run a server for scheduling regular EBS snapshot and AMIs scripts. AWS Lambda gives option to save our function on AWS itself and CloudWatch has an option to schedule the functions. In this project, I am trying to leverage both and achieve a solution for backup using AWS native services with $0 cost !!!
- AmiBackup
- AmiRetention
- EbsBackup
- SnapshotRetention
- Name - Any AWS supported name
- CreateAmiBackup - ['y', 'yes', 't', 'true', '1']
- AmiBackupDates (optional) - [1-31]/Daily/[sun-sat]/[Sunday-Saturday]. Default 1
- BackupWindowUTC (optional) - [0-23]. Default 0
- AmiRetentionDays (optional) - Any integer. Default 3
- ExcludeDevices (optional) - /dev/sd[b-z]. Default None
- TransferAmi (optional) - Future option
- Name - Any AWS supported name
- BackupWindowUTC - [0-23]
- SnapshotRetentionDays(optional) - Any integer
Give following role for EbsBackup and SnapshotRetention
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Sid": "SnapshotPermissions",
"Effect": "Allow",
"Action": [
"ec2:CreateSnapshot",
"ec2:CreateTags",
"ec2:DeleteSnapshot",
"ec2:DescribeVolumes",
"ec2:DescribeSnapshots"
],
"Resource": [
"*"
]
}
]
}
Give this role for AMI backup and AMIRetention functions
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Sid": "AmiPermissions",
"Effect": "Allow",
"Action": [
"ec2:CreateImage",
"ec2:DescribeInstances",
"ec2:CreateTags",
"ec2:DeregisterImage",
"ec2:DeleteSnapshot",
"ec2:DescribeImages"
],
"Resource": [
"*"
]
}
]
}