modernisation-platform icon indicating copy to clipboard operation
modernisation-platform copied to clipboard

Automatically schedule customer EC2 instances to stop / start

Open dms1981 opened this issue 2 years ago • 1 comments

User Story

As a modernisation platform engineer I want to schedule the operating hours of modernisation platform EC2 instances So that we can deliver a sustainable platform

User Type(s)

Modernisation Platform engineer Modernisation Platform customer

Value

Non-production instances should not need to be run outside of office hours Production instances should not need to be run outside of service hours Shutting down instances when they are not required offers better value for money to the Ministry of Justice, aligns with our sustainability goals of not consuming resources when they are not required, and aids with work/life balance

Questions / Assumptions / Hypothesis

  • [ ] Is delivering the AWS Instance Scheduler CloudFormation template through Terraform an option? Yes, but not a particularly palatable one. We use Terraform to deliver and manage our infrastructure. Using Terraform to deliver a CloudFormation template feels like an opaque solution.
  • [ ] Is using AWS Systems Manager to control the startup and shutdown of instances an option? Yes, but again this is an option with drawbacks. Centrally managing the maintenance windows across accounts is not possible, so automations would need to be externally triggered which increases the complexity of the solution
  • [x] Is using a Lambda function an option? Yes, although this would require the team to maintain the Lambda function. However, of the three most obvious solutions this one presents the best balance.
  • Should this be contained in a separate module? (EG. modernisation-platform-terraform-lambda-scheduler)
  • What language should be used? (Golang, in line with ADR)
  • This should be done based on a key/value tag that customers can omit / overwrite if they decide not to use the scheduler (EG. availability:weekdays)
  • Necessary IAM role for the function to adopt will be provided in default build of customer environment

Definition of done

  • [ ] Architectural decision record has been updated
  • [ ] Module created and tested in development environment (EG, Sprinkler)
  • [ ] another team member has reviewed
  • [ ] tests are green
  • [ ] docs have been updated

Reference

How to write good user stories Scheduling shutdown AWS EC2 at night

dms1981 avatar Jun 06 '22 08:06 dms1981

See https://github.com/ministryofjustice/modernisation-platform/issues/2054 - this story will ensure that the scheduler has the appropriate limited permissions it will require

dms1981 avatar Jul 28 '22 13:07 dms1981

https://github.com/ministryofjustice/modernisation-platform-instance-scheduler

gfou-al avatar Sep 30 '22 09:09 gfou-al

ADR here https://github.com/ministryofjustice/modernisation-platform/blob/main/architecture-decision-record/0021-use-a-go-lambda-for-instance-scheduling.md

davidkelliott avatar Oct 05 '22 15:10 davidkelliott