HomeCloud Computing

AWS Cloud: Saving Dollars with EC2 scheduling

AWS Cloud: Saving Dollars with EC2 scheduling
Like Tweet Pin it Share Share Email

In this session discussion and demo is on how to make AWS Cloud more affordable with aws ec2 scheduling. 

Introduction /Background

In most of Enterprises setups, there are minimum 02 environments. 

  • Production
  • Non-Production (Development, SIT, NPE etc).

Production workload generally runs 24 x 7 to cater the business. But Development environments are not used at all times.

When the IT setup is using Public cloud as the platform, cost is a big consideration and it’s objective to reduce the operational costs w/o impacting the business.

AWS cloud is flexible as they charge only for the resources we utilize.  For a quick example on the EC2 instance running cost

Instance TypeUSD/Hr24*7 / MonthSelective Usage / Month
m4.2xlarge0.561403 USD111  USD


*Selective Usage: Weekdays 9:00 AM to 05:00PM

For Development instances which are not required 24 x 7, saving can be done by stopping all development instances after business hours and weekend, as developers may be not using the instances that particular time. This can save a big amount from cloud expenditures.

How this can be Achieved

  • Instance Stop/Start can be scheduled using AWS Data Pipeline service. AWS charge for this service.
  • You can use your custom script/software to manage the instance stop/start.

I have written a small shell script to demonstrate, how you can manage the instance stop/start at your level. On the server where configuring this script, need to have aws cli setup.

How this script works.

  1. Checks if instance have TAG “Key – NightSleep” and its Value. (possible values are “True|False”)
  2. When script called with option “start” – script starts all instances with TAG “Key/Value” = “NightSleep/True”
  3. When script called with option “stop” – script stops all instances with TAG “Key/Value” = “NightSleep/True”
  4. if Instance, does not have “Key/Value” = “NightSleep/True” , this script will do NOTHING.

This script can be scheduled ( *nix cron) to perform the following

Stop all Instances with NightSleep/True        –        After business hours

Start all Instances with NightSleep/True        –        Weekdays (say 9:00AM )

Lab Setup Today:

———————————————————————————-

Instance ID          :        i-02ab75cd9c4e9cce1

Tags                        :

Env                          :        Non-Prod

NightSleep            :        True

———————————————————————————-

Instance ID          :        i-02ab75cd9c4e9cce1

Tags                        :

Env                          :        Non-Prod

NightSleep            :        True

———————————————————————————-

Instance ID          :        i-09d5c649085223b0b

Tags                        :

Env                          :        Prod

NightSleep            :        False

———————————————————————————-

Script

[[email protected] /]# /usr/local/bin/awscostsaving.sh

Error occoured : valid options are stop/start/status

Crontab Entries

## Starts the Instances at 09:00 AM Mon-Friday

00 09 * * 1-5 /usr/local/bin/awscostsaving.sh start

## Stops the Instances at 05:30 PM Mon-Friday

30 17 * * 1-5 /usr/local/bin/awscostsaving.sh stop

 

Conclusion: This is the good way to do aws ec2 scheduling using with scripts. Please go through the video and check the script details.

Comments (1)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.