AWS EC2 scheduling

AWS EC2 scheduling is now managed by a service called the AWS Instance Scheduler. This was launched in early 2018 and replaced the old AWS EC2 scheduler. The basic idea behind it, however, is essentially the same.

The basics of AWS EC2 scheduling

Possibly the most fundamental principle of the public cloud (at least as far as cost-optimization is concerned) is the idea that you only use what you actually need when you actually need it. In theory, you can just leave employees to spin up the resources they need when they need them and shut them back down again when they’re finished. In practice, this approach almost guarantees that instances will be left running when they’re not required, which is why AWS introduced the concept of scheduling.

AWS EC2 scheduling is exactly what it sounds like. It allows you to set a time of operation for an AWS EC2 instance at the start of which it will be automatically spun up and at the end of which it will be automatically shut down. You can even prevent people from opening instances during the “out-of-hours” time.

AWS EC2 scheduling in more detail

The AWS Instance Scheduler allows you to schedule by time, day of the week, days of the month and months of the year. What’s more, you can create multiple schedules and then use tags to define which schedule should be applied to which instance.

Tagging is one of AWS’ most useful features. We aren’t going to discuss it in-depth here, but essentially it works much the same way as tagging on social media.

One of the great features of the AWS Instance Scheduler is that it can be configured to take time zones into consideration. This can make life a whole lot easier when you’re working across different geographical areas. Standardizing on one agreed time zone is fine in theory, but in practice, again, people forget or get confused, especially at periods when clocks are changing.

Once your scheduling is in place, you define a time interval, let’s say every five minutes, according to which Amazon CloudWatch will trigger an AWS Lambda function which will pull the scheduling information, check the state of each defined instance against the details given in the schedule, and start or stop instances as necessary.

Setting up AWS EC2 Scheduling

Most of the process for setting up AWS EC2 scheduling is fairly self-explanatory and relies on nothing more than a knowledge of who uses what resources at what time (and preferably why). There is, however, one field that might give you pause for thought and that is the “enforced” field.

In short, this field allows you to determine whether or not a resource can be manually started outside the defined running period and/or manually stopped within the defined running period. Sadly it is currently not possible to allow instances to be manually stopped within the defined running period but not manually started outside the defined running period. 

Your decision as to whether or not to set this field to true will depend on a combination of your priorities and your ability to implement necessary changes promptly. For example, if your priority is to stop people from wasting resources by failing to shut down instances when they are out of use, then you probably want to set this field to true, especially if you’re confident that you can react quickly if any scheduling changes become necessary.

On the other hand, if you know your business might need to react quickly to events and you’re not confident that there will always be someone around to make prompt updates to scheduling, then you might want to leave it set to false, but have a clear process in place for spinning up events “out of hours”, including a process to have them shut down again and a person who will be held accountable for making sure that this actually happens.

You may be able to be more strict with development and test environments than you can with your production environment. Realistically, development and test environments are only likely to be used during working hours and are unlikely ever to be used in an emergency. That being so, you can often afford to take a firm stance regarding enforcing scheduling. 

With a production environment, there’s always the possibility of an emergency, which means you often want to allow some degree of flexibility. That said, you will still want (and need) robust processes in place to prevent this flexibility from being abused, even if only through laziness rather than deliberate malice.

The cost of the AWS Instance Scheduling Pricing Module

AWS Instance Scheduler costs $5 per month (in AWS Lambda charges) for each schedule, plus $0.90 per schedule or scheduled service to track the schedule actions as an Amazon CloudWatch metric.

aws ec2 pricing model