I want an alarm to operate only overnight between 18:00 and 08:00 so I can keep an EC2 instance running all the working day and stop overnight if no-one is using it. Is this possible?
Asked
Active
Viewed 2,124 times
2 Answers
0
Of course this is possible but you need to write your own script to imitate this scenario, there are ec2-api's available which will help you make this happen.
What you can do:
- Write a cron script that will start/stop your instances.
- Write a script that will take an input from cloudwatch to take a call on stopping the server if there no request for a
n
period.
Hope this helps.

Rakesh Sankar
- 9,337
- 4
- 41
- 66
-
Ah OK. So I can't achieve it by a setting on the AWS dashboard for Alarms. I'll need to learn more about the API then. Thanks! – N Burnett Dec 15 '13 at 10:58
0
You can automate this by creating an EventBridge rule where you specify a cron or schedule expression that runs a Python lambda function on specific timings.
Then, you can use your Lambda function to enable or disable an alarm(s) according to your required schedules.
disable_alarm = client.disable_alarm_actions(AlarmNames=alarm_names)
Here's a good tutorial: https://medium.com/geekculture/terraform-structure-for-enabling-disabling-alarms-in-batches-5c4f165a8db7

x89
- 2,798
- 5
- 46
- 110