Contact Us

Contact Us



Pleas confirm by checkbox


CloudTechnical

Schedule Daily EC2 instance stop using CloudWatch Events

Author_img
By Aditya Doke March 22, 2017

Purpose

Infra/Dev-ops team do have instance created for POC/Demo/testing purpose which we need to stop daily (office off-hours) or during weekends for cost saving purpose. As this adds an overhead for us to daily stop the instance manually before leaving office and sometimes we might forget to stop the instance which again will add up the cost.So there was a demand to automate this process in order to save cost.

Solution

Now we have a feature in AWS to schedule a job in CloudWatch Events to stop a running instance daily or during weekend which is used for POC/Demo/testing purpose without any manual intervention.

Use-case

I have to schedule it for one of my POC “poc_rundeck” instance to stop automatically daily during office off hours say after 9pm IST which will help us in saving cost .

Step One—Create a Rule

click on “create role” in CloudWatch Events Rules

CW1

Step Two—Schedule a Cron inside Rule

Select Schedule

CW2

Set Cron expression to ” 30 15 * * ? * ” , In this use case we have set it to 15:30 GMT which is 9:00 PM IST . Link about CloudWatch Events schedules.

CW3

Step Three – Add Targets

Click “Add target”

CW4

Select “Built-in target”

CW5

Set Action as “Stop an EC2 instance”

CW6

Select the instance ID of machine to stop

Add another Target “SNS topic” for email Notification

CW7

Set the Topic to which you wish to send notification, In this use-case we select “infra”

CW8

Step 4 —Configure Details

CW9

Enter name and description and set State to Enabled as shown.

CW10

Give AWS Permissions by either creating a new role or selecting the existing role as shown.

CW11

Click “create rule” to complete the configuration step.

CW10

You will see a new rule created “rundeck_stop” and schedule in Rules dashboard

CW13

Detail View of Rule created

CW14

“poc-rundeck” Instance gets stop automatically at 9 pm IST

CW15

If you plan to work late night in office on your POC instance you can disable the rule by editing it in order to avoid instance getting stopped by CloudWatch events.


Related posts
AWS Lambda Automated Deployment
Cloud

AWS Lambda Automated Deployment

By shekhar.wagh March 08, 2018
Go ServerLess with Firebase cloud functions
App Development

Go ServerLess with Firebase cloud functions

By shekhar.wagh May 04, 2017
CLOUD GIANTS RACE :AWS vs AZURE vs GOOGLE CLOUD
Cloud

CLOUD GIANTS RACE :AWS vs AZURE vs GOOGLE CLOUD

By shekhar.wagh March 24, 2017
One-Click Deployment with AWS CodeDeploy
Cloud

One-Click Deployment with AWS CodeDeploy

By shekhar.wagh March 22, 2017
Tech trends for 2016 and how startups would capitalize on them
Big Data

Tech trends for 2016 and how startups would capitalize on them

By shekhar.wagh March 15, 2016
Build a Custom Solr Filter to Handle Unit Conversions
Big Data

Build a Custom Solr Filter to Handle Unit Conversions

By shekhar.wagh March 14, 2016
Multi-tenancy in Cloud Application through Meta Data Driven Architecture
Cloud

Multi-tenancy in Cloud Application through Meta Data Driven Architecture

By shekhar.wagh September 25, 2013
10 things to do while migrating an ASP.NET App to Azure
Cloud

10 things to do while migrating an ASP.NET App to Azure

By shekhar.wagh September 24, 2010

Stay updated

Get the latest creative news from Fubiz about art, design and pop-culture.