Skip to content

danzelziggy/AWS-AMI-Automated-Creation-Deletion

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWS AMI Automated Creation & Deletion System

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.

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.

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.

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

  1. Select a schedule you like to setup. Ideally the script has to run every day

  2. Paste the script for createAMI.js

  3. Create a new role and paste the roles/roles.json also increase timeout.

  4. Save this and follow step above again now using deleteAMI.js.

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

  1. 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.

Notes

About

Automated AMI creation & deletion using serverless AWS Lambda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%