Scheduled backups of EBS volumes using Lambda - provisioned via Terraform
- Install Terraform
- Have
zip
available on the PATH
- Make sure to have your AWS credentials set up properly. Normally these are picked up from the following standard environment
variables:
AWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
andAWS_DEFAULT_REGION
. Alternatively, you can enter these parameters directly inmain.tf
but this is not recommended. - (optional) Review and adjust the schedule and the backup retention policies in
lambda.tf
andlambda_ebs_backup.py
- Run the following commands to provision the lambda function to AWS:
./build.sh
- (optional)
terraform plan
terraform apply
- Add the tag
Backup
to all volumes you want to include in the backup process. The value of the tag is indifferent, use e.g.daily
.
Run terraform destroy
to clean up and delete all associated resources from AWS. Note that this needs the terraform.tfstate
that was created during the provisioning step above.
- AWS Lambda requires the function package to be uploaded as a zip file. However, Terraform does not provide any support in creating a zip file yet, hence we need the extra 'build' step.
- Currently the backup schedule as well as the backup retention policies are hard-wired into the code. A possible improvement would be to have them configurable.