Many organizations leave development, testing, and staging instances running continuously even though they are needed only during business hours. This article outlines a Terraform solution that starts and stops EC2 instances on a schedule using EventBridge, Lambda, and IAM.
The problem: idle EC2 costs
Non-production environments often do not need 24/7 availability. Scheduling a medium-sized instance for business hours instead of continuous use can significantly reduce its monthly cost.
Terraform-managed scheduling
The solution uses EventBridge rules and targets to invoke a Lambda function on a chosen schedule. Terraform manages the provider configuration, input variables, scheduled rules, IAM roles and policies, Lambda function, and permission for EventBridge to invoke it.
The intent is to make the schedule explicit and repeatable rather than dependent on a manual operational task. IAM permissions should remain scoped to the instances and actions the scheduler actually requires.
Operational use
Before applying a schedule, identify workloads that can safely stop, select a timezone-aware business policy, and test the start and stop behavior in a non-production account. The schedule is an optimization control, not a substitute for workload ownership or availability requirements.