All Collections
Getting Started
Amazon Web Services
Changing EC2 Instances Down On Weekends
Changing EC2 Instances Down On Weekends

Strong Monday through Friday, weaker on weekends

Matt Houser avatar
Written by Matt Houser
Updated over a week ago

If your EC2 instances have periods of time where they are heavily used, and other times where they are lightly used, they can benefit from having their instance types changed by schedule.

For example, if your EC2 instance requires a m4.xlarge  Monday through Friday, but on weekends, it can get by on a t2.medium, then you can lower your EC2 costs by using an m4.xlarge only through the week.

In this guide, we are going to create an action that will change our EC2 instances to an t2.medium . Here, we assume that the "normal" EC2 instance type is the "higher" type, such as m4.xlarge .
​ 
There are many ways to do this, here we'll show one of the most flexible methods.
​ 
Here, we are going to use a single "Change EC2 Instances" action to create an action that will change EC2 instances to t2.medium at 8 PM on Friday and revert them back at 8 AM on Monday. Each Friday, Skeddly will look for EC2 instances in your selected region that has a resource tag named skeddly:change-schedule  and value 0800-t2.medium .
​ 
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

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 "Change EC2 Instances".
4. In the "Name" field, give your action a friendly name. This is for your reference.
5. In the "Time of Day" field, put 8:00 PM. This will be the time that the EC2 instances will first change.
6. In the "Time Zone" field, choose your local time zone. The EC2 instance will change at 8: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 Friday. Leave all other days unselected.

So far, we have defined our schedule so that it will execute at 8:00 PM, but only on Friday.

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

Now we are going to define how Skeddly will select the EC2 instances to change.

10. In the "Instance Identification Method" field, choose "Resource Tag". This tells the action to find EC2 instances by matching resource tags.
11. In the "Resource Tag Name", put "skedd;y:change-schedule". This is the name of the resource tag that will be used to find EC2 instances to change.
12. In the "Resource Tag Value", put "Equals" and "friday-2000-t2.medium". This is the value of the resource tag that must match.

In this tag value, we included the day, time of day (24-hour notation), and instance type to which we are going to change. This is so you could have other schedules at 8 PM that change to other instance types as well. You could use any tag value you'd like, as long as it matches.

13. Set the "Instance Type" field to "t2.medium".
14. Set the "EBS Optimized" field to "No".

At this time, the action is now configured to change EC2 instances to t2.medium  on Friday evenings, but it will not revert them on Monday yet. We also disable "EBS Optimization" on the EC2 instances. This is because the t2 instance family does not allow EBS Optimization to be enabled.

15. In the "Revert the Changes" field, check the checkbox.
16. For "Running Duration", use a value of 2 days, 12 Hours because 8 PM to 8 AM is 12 hours, and the weekend is 2 days long.
17. Click the "Save" button.

The action is 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: IAM Policy Generator

Adding EC2 Instances to Your Schedule

Each morning, Monday through Friday, Skeddly will execute our action and it will look for EC2 instances to change. 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:change-schedule".
8. In the "Value" column, put "friday-2000-t2.medium".
9. Click the "Save" button.

Remember, tag comparison is case-sensitive.

When the action starts at 8 PM, Skeddly will make note of the instance's current instance type (eg. m4.xlarge ) and remember it. It will then change the instance to an t2.medium. At the time to revert, the instance will be reverted by to a m4.xlarge.

Multiple EC2 instances can be part of the same schedule, even if they are not the same originating EC2 instance type. They will all be changed to t2.medium , then they will each be reverted to their own original type.

Since we are changing the EC2 instance type "down", the EC2 instances should be in the higher instance type when the action executes.

Important Note:

Not all EC2 instance types support optional EBS Optimization.

For example, t2 instance types do NOT support EBS optimization. And m4 instance types require EBS optimization.

When changing EC2 instance types, you may also need to change the "EBS Optimized" field as well.

Did this answer your question?