All Collections
Getting Started
Amazon Web Services
Changing EC2 Instances Up Monday - Friday
Changing EC2 Instances Up Monday - Friday

Strong during business hours, weaker overnight and 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  during business hours, but on weekends, it can get by on a t2.medium, then you can lower your EC2 costs by using an m4.xlarge only when needed.

In this guide, we are going to create an action that will change our EC2 instances to an m4.xlarge . Here, we assume that the "normal" EC2 instance type is the "lower" type, such as t2.medium .
​ 
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 m4.xlarge at 8 AM and revert them back at 7 PM. Each morning, Skeddly will look for EC2 instances in your selected region that has a resource tag named skeddly:change-schedule  and value 0800-m4.xlarge .
​ 
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 AM. 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 AM in the selected time zone.
7. Set the "Repeat Type" field to be "Daily".
8. In the "Days of the Week" field, choose Monday, Tuesday, Wednesday, Thursday and Friday. Leave Saturday and Sunday unselected.

So far, we have defined our schedule so that it will execute daily at 8:00 AM, but only Monday through 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 "0800-m4.xlarge". This is the value of the resource tag that must match.

Here, we included the instance type to which we are going to change. This is so you could have other schedules at 8am that change to other instance types as well.

13. Set the "Instance Type" field to "m4.xlarge".
14. Set the "EBS Optimized" field to "Yes".

At this time, the action is now configured to change EC2 instances to m4.xlarge  in the morning, but it will not revert them in the evening yet. We also enable "EBS Optimization" on the EC2 instances. This is because the m4 instance family requires EBS Optimization to be enabled.

15. In the "Revert the Changes" field, check the checkbox.
16. For "Running Duration", use a value of 11 Hours because 8 AM to 7PM is 11 hours.
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 "0800-m4.xlarge".
9. Click the "Save" button.

Remember, tag comparison is case-sensitive.

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

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 m4.xlarge , then they will each be reverted to their own original type.

Since we are changing the EC2 instance type "up", the EC2 instances should be in the lower 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?