AWS AMI Automated Creation & Deletion System
Creating an AMI automatically snapshots all the associated EBS volumes for that instance. This makes instance recovery much more reliable and faster. A daily or weekly backup schedule is recommended for instances and to make sure you have a backup if ever needed. The system also removes the automatically created AMIs and any associated snapshots as per the settings.
Update 31 March 2017 - Added feature to prevent reboot while creating AMI. Add a tag BackupNoReboot with value true if want to avoid rebooting that instance.
Update December 2018 - Replaced screenshots to reflect AWS Console changes.
Setup / Installation of the Lambda script
Go to the AWS Lambda Console and click Create function.
Give the custom role a name and paste the contents of roles.json into the edit box.
Paste the contents of createAMI.js into the edit box.
Configure the Rule:
- Provide a rule name and description.
- Set the event pattern or schedule.
- The cron expression showed below will run at 2AM every day.
- Finish by clicking Add at the bottom.
Create a second function named deleteAMI.
Follow the same basic steps as above, but this time:
- Use deleteAMI.js
- Use the existing lambda Role.
- Use the existing CloudWatch Rule.
Setting the tags for EC2 instances
Set the tags on the instances you want backed up.
- Backup: yes
- BackupRetentionDays: a positive integer
- BackupNoReboot: true (this tag is optional - reboot will happen unless the tag is present and value is true)
- This is another open source project bought to you by Webdigi - Web development, London.
- Please submit your pull requests or suggestions to improve this script.
- You can read about updates to this project on our blog - AWS Instance Automated AMI Creation & Deletion System