DEV Community

Cover image for Stop and Start instances using the AWS Instance Scheduler - STOPINATOR
Anuvindh for AWS Community Builders

Posted on • Edited on

Stop and Start instances using the AWS Instance Scheduler - STOPINATOR

DAY 6 - STOPINATOR- Start and Stop EC2 at predefined times 🔴🟢

☁️100 days of Cloud- Day Six
Follow Me on Twitter

Cover

Tweet This Blog - Read on GitHub - Read On iCTPro.co.nz


Stopping and starting EC2 instances automatically

Using Instance scheduler you can start and stop instance automatically using Cloud formation

Prerequisites

Installing Scheduler CLI

curl "https://s3.amazonaws.com/solutions-reference/aws-instance-scheduler/latest/scheduler-cli.zip" -o "scheduler-cli.zip"
Enter fullscreen mode Exit fullscreen mode

Unzip

unzip scheduler-cli.zip
Enter fullscreen mode Exit fullscreen mode

Install

sudo python setup.py install
Enter fullscreen mode Exit fullscreen mode

Check

scheduler-cli --version
Enter fullscreen mode Exit fullscreen mode

Creating AWS CloudFormation Stack

Launch Solution , or download template

Comments ScreenShots
Click on to Launch Solution Stack launch
Enter Stack Name Image StackName
Choose your frequency (in Mins) Image frequency
Enable CloudWatch Logs Image Cloudwatchlogs
Start & Stop tag Image startandstop
keep everything default and acknowledge then click create stack Image Stack creation

Creating Start and Stop Period

Go to instance and paste this script

scheduler-cli create-period --stack Ec2instanceScheduler --region ap-southeast-2 --name mon-fri-9-5 --begintime 9:00 --endtime 16:59 --weekdays mon-fri
Enter fullscreen mode Exit fullscreen mode

Here i am setting up to start time 9 am and stop time 4.59 Pm from Monday to Friday.

Now go to AWS Console and open the DynamoDB.

Click on to Tables and choose the config table .
Then Choose the Items , and check for QuickPeriod appears under Name.

Creating Schedule for the period

Each schedule must contain at least one schedule period, it defines the time instance should run.

SSH into ec2

scheduler-cli create-schedule --stack Ec2Stopinator --name QuickSchedule --region ap-southeast-2 --periods QuickPeriod --timezone UTC+1300

Enter fullscreen mode Exit fullscreen mode

goto the DynamoDB.

Click on to Tables and choose the config table .
Then Choose the Items , and check for QuickSchedule appears under Name.

Tagging the Schedule

Now go to ec2 and select Manage tags
Key = Schedule
Value = QuickSchedule

🎉 Congratulations 🎉 you have successfully configured STOPINATOR

Top comments (0)