Reputation: 33
I want to set a schedule for my EC2 to turn on twice a day at two specific times - at 12:00AM and at 12:00PM - and turn off after 30mins (at 12:30PM and 00:30AM).
I created one EC2 Scheduler/Table (tagname: Schedule) and I then setup two schedules in the config file (refresh-1 and refresh-2), which include the two periods/hours.
When I add the "key" and "value" fields to my "Manage Tasks" page in EC2, I get an error message saying that I can only specific a unique tag key.
Does this mean that I need two separate EC2 Schedulers/Tables in order to turn on/off my EC2 at two different times? For instance:
What's the simplest solution to set this up, trying to leverage just one EC2 Scheduler/Table?
NB: I'd like to use Lambda/DynamoDB, not other solutions preferably.
Thanks!
Upvotes: 1
Views: 297
Reputation: 8097
The error you are seeing is because you cannot have two EC2 tags with the same key. So you may only have a single Schedule
tag on each EC2 instance.
After reviewing the EC2 Instance Scheduler documentation, you should create two periods instead of creating two schedules. One period for 12:00am-12:30am and another for 12:00pm to 12:30pm. Then create one schedule that references both periods.
Using the CLI it would be something like:
$ scheduler-cli create-period --name noon30 --begintime 12:00 --endtime 12:30 --stack Scheduler
$ scheduler-cli create-period --name midnight30 --begintime 00:00 --endtime 00:30 --stack Scheduler
$ scheduler-cli create-schedule --name my-refresh --periods
noon30,midnight30 --timezone Europe/London --stack Scheduler
Upvotes: 1
Reputation: 269101
Instead of using the AWS Instance Scheduler, you might be interested in the Simple EC2 Stopinator in Lambda - DEV Community that I created. It uses a single Lambda function and an IAM Role, nothing else.
It can specify a duration after which the instance should be terminated (good for sandbox testing), and it can schedule instance stoppage.
It should be fairly easy to modify to set a Start Time too.
Upvotes: 0