Skip to main content
Creating Daily AMI Images

Creating actions to create and delete AMI images

Matt Houser avatar
Written by Matt Houser
Updated over 5 years ago

Skeddly can create daily AMI images for you automatically. In addition, it can delete old images after a pre-determined number of days.

Here, we are going to use a single "Create Multiple AMI Images" action to create AMI images at 2 AM. Each morning, Skeddly will look for EC2 instances in your selected region that has a resource tag named "skeddly:ami-schedule" and value "0200".

Once configured, you can add EC2 instances to your schedule by simply adding the resource tag to your EC2 instance. This can be accomplished using CloudFormation or other DevOps tools.

Prerequisites

  • A Skeddly account

  • An AWS credential (IAM role or IAM access key) registered with Skeddly

Setting Up Skeddly

Creating the Backup Action

  1. Go to the Actions list by clicking "Actions" then "Actions".

2. Click the "Create New Action" button.
3. In the action list, find and click on "Create Multiple AMI Images".
4. In the "Name" field, give your action a friendly name. This is for your reference.
5. In the "Time of Day" field, put 2:00 AM. This will be the time that the AMI images will be created.
6. In the "Time Zone" field, choose your local time zone. The AMI images will be created at 2:00 AM in the selected time zone.
7. Set the "Repeat Type" field to be "Daily".
8. In the "Days of the Week" field, choose Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.

So far, we have defined our schedule so that it will execute daily at 2:00 AM.

9. In the "Credentials and Regions" section, select the AWS credentials and AWS regions in which your EC2 instances live.

Now we are going to define how Skeddly will select the EC2 instances from which AMI images will be created.

10. In the "Instance" field, choose "By Comparison Filters". This tells the action to find EC2 instances by comparing resource tags.
11. Under "Resource Tag Comparisons", click "Add Comparison". A new, empty tag comparison should appear.
12. In the "Resource Tag Name", put "skeddly:ami-schedule". This is the name of the resource tag that will be used to find EC2 instances to backup.
13. In the "Resource Tag Value", put "Equals" and "0200". This is the value of the resource tag that must match.
13. We recommend that your stop your EC2 instances when the AMI images are created. This is not required though. To stop your EC2 instances, make sure the checkbox labelled "No Reboot" is not checked.
14. For easy identification later, we want to add some resource tags to the images that are created. In the "EC2 Tags" field, add a tag named "skeddly:retention" and value of "7".

Creating the Deregister Action

In this example, we will delete images are are older than 7 days. The delete will happen only once per week, on Saturdays.

1. Go to the Actions list by clicking "Actions" then "Actions".
2. Click the "Create New Action" button.
3. In the action list, find and click on "Deregister AMI Images".
4. In the "Name" field, give your action a friendly name. This is for your reference.
5. In the "Time of Day" field, put 11:00 PM. This will be the time that the AMI images will be deleted.
6. In the "Time Zone" field, choose your local time zone. The AMI images will be deleted at 11:00 PM in the selected time zone.
7. Set the "Repeat Type" field to be "Daily".
8. In the "Days of the Week" field, choose only Saturday.

So far, we have defined our schedule so that it will execute Saturdays at 11:00 PM.

9. In the "Credentials and Regions" section, select the AWS credentials and AWS regions in which your AMI images are being created.

Now we are going to define how Skeddly will select the AMI images to delete.

10. In the "Image Identification Method" field, choose "By Resource Tag". This tells the action to find AMI images by matching resource tags.
11. In the "Resource Tag Name", put "skeddly:retention". This is the name of the resource tag that will be used to find AMI images to delete.
12. In the "Comparison", put "Equals" and "7". This is the value of the resource tag that must match.
13. For the "Delete Scheme" field, select "Simple, Oldest First".
14. For the "Older Than" field, put "7". This means only images older than 7 days will be deleted.
15. By default, "Test Mode" is enabled. When enabled, the actions will execute on schedule, but images will not be deleted. This lets you examine the logs to ensure the correct AMI images are being deleted. Once you are happy with how the action is executing, modify your action configuration to disable "Test Mode".

The actions are complete.

However, by default, Skeddly won't have permissions to execute this action yet. So we need to use Skeddly's IAM Policy Generator to generate a new policy. Instructions for that can be found here: http://help.skeddly.com/credentials/amazon-web-services/iam-policy-generator

Adding EC2 Instances to Your Schedule

Each morning, Skeddly will execute our action and it will look for EC2 instances to backup. To add EC2 instances to this schedule, do the following in the AWS Management Console:

1. Go to the EC2 Management Console.
2. Go to the Instances list by clicking "Instances" on the left navigation pane.
3. Select the EC2 instance you want to add to the schedule.
4. In the details panel, click the "Tags" tab. This should show the list of existing resource tags.
5. Click the button titled "Add/Edit Tags".
6. Click the "Create Tag" button. A blank tag row should appear in the grid.
7. In the "Key" column, put "skeddly:ami-schedule".
8. In the "Value" column, put "0200".
9. Click the "Save" button.

Remember, tag comparison is case-sensitive.

Did this answer your question?