m-chandler / factorio-spot-pricing

Factorio Deployment to AWS
MIT License
98 stars 25 forks source link

Instance Scheduler #18

Open robertmassaioli opened 2 years ago

robertmassaioli commented 2 years ago

Great AWS template! Saves me the effort of having to do this myself.

I have a feature idea: could you integrate an EC2 Scheduler into this such that we only run this EC2 instance at legitimate times that I would actually Play Factorio.

For example, I would only ever play Factorio from 5pm-9pm Weekdays and 7am-Midday on Weekends. If the EC2 instance automatically came up during those times it would prevent me from having to manually update the stack. Cheers!

robertmassaioli commented 2 years ago

Even just documentation for how to use something like https://aws.amazon.com/solutions/implementations/instance-scheduler/ in tandem with this would be useful.

m-chandler commented 2 years ago

Hi @robertmassaioli glad you like it.

You probably don't want that instance scheduler from AWS, last time I looked it was expensive to run and regardless, from memory it doesn't support auto scaling groups - it just turns on and off individual instances.

We don't need that much complexity. I should be able to have a look in a little bit (you can look if you like and submit a PR); you probably want to add a couple of AWS::AutoScaling::ScheduledAction resources to the CloudFormation template. One of these resources would let you set the auto scaling group to desired/min/max 1/1/1 at the start of the day which will start the server, and the other 0/0/0 at the end of the day. Note that the Recurrence property will be a cron in UTC time, not your local time.

If you submit a PR, just be sure to make the feature optional via params / update docs etc.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-as-scheduledaction.html