UPDATE: 14 JUN 2017 – In step 5 below, please do select 5 minutes timeout for the script. We did have a few issues for users who had a lot of instances taking over the standard 2 minutes for the script to run.

Just a quick blog post to link our new Github script on automated AWS AMI management system.

Motivation

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.

Setup / Installation of the Lambda script (one time setup)

1) Setting up the Lambda script by opening the Lambda console



2) Select “CloudWatch Events – Schedule” and click Next

3) Select a schedule you like to setup. Ideally the script has to run every day 4) Paste the script for createAMI.js (See github link above)

5) Create a new role and paste the roles/roles.json (See github link above) also increase timeout.

6) Save this and follow step above again now using deleteAMI.js (See github link above).

Setting the tags for EC2 instances (repeat for each instance)

1) Login to your AWS console and open the EC2 section. Then select the instance

2) Select the add or edit tags as per settings

3) 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 (Saturday), 1 (Monday) and all the way to 6 (Sunday). You can set value to say 012 which means run on Saturday, Monday and Tuesday. You can set just 6 to run only on Sunday.

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.