A simple AWS lambda project to help automate creation and deletion of AMIs. The scripts are written in JavaScript and will run on the the serverless AWS Lambda platform.
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 AutoDigiNoReboot with value true if want to avoid rebooting that instance.
-
Select "CloudWatch Events - Schedule" and click Next
-
Select a schedule you like to setup. Ideally the script has to run every day
-
Paste the script for createAMI.js
-
Create a new role and paste the roles/roles.json also increase timeout.
-
Save this and follow step above again now using deleteAMI.js.
-
Login to your AWS console and open the EC2 section. Then select the instance
-
Select the add or edit tags as per settings
- Set the three tags with the following Keys & Value a) Key: AutoDigiBackup with Value: yes. This marks the instances that need to be backed up. b) Key: AutoDigiBackupRetentionDays with Value: from 1 to as many days as you want the backup to be stored. c) Key: AutoDigiBackupSchedule with Value: * (for every day) or a mix of number from 0 (Sunday), 1 (Monday) and all the way to 6 (Saturday). You can set value to say 012 which means run on Sunday, Monday and Tuesday. You can set just 6 to run only on Saturday.
Example below is set to create the AMI every day
Save the settings that are approriate for this instance and then save the tags. Please repeat steps 1-3 for all instances that you like to be included.
- 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