How to stop EC2 instances automatically when nobody is using them

5 min read
An empty office at dusk: a row of dark desks and pushed-in chairs, one small emerald light going out on a server cabinet by the window, deep navy tones.

Short answer: There are three common ways to stop an EC2 instance automatically: a schedule, an alarm on low usage, and a lease. A schedule stops machines at fixed hours, and an alarm stops them when they look quiet. With an Idlefy lease the machine stays off by default, starts when a person asks for it, and stops itself when the time that person set runs out.

How do you stop an EC2 instance automatically?

You stop an EC2 instance automatically by giving something other than a person the job of calling the stop. On AWS the usual options are an EventBridge schedule with a Lambda function, a CloudWatch alarm with a stop action, or a lease managed by a tool such as Idlefy. A schedule answers “what time is it”, an alarm answers “does this machine look busy”, and a lease answers “did someone ask for this machine, and for how long”. Stopping keeps the instance and its persistent disks, so the same machine comes back on the next start. Compute billing stops with the machine, and the disk keeps costing its normal rate. Stopping is different from terminating, which deletes the instance.

What do schedules and alarms miss?

A schedule keeps a machine running through every working hour, used or not, and it stops work that runs past the fixed time. A developer on vacation still has a machine that starts every morning. An alarm stops a machine that looks quiet, so a long background job that uses little of the machine can be stopped by mistake. It also needs a threshold you tune, and one alarm per instance. Both methods have to be built and kept up to date: a new account, region or instance is one more thing to remember. Neither tells the person before the machine goes down, unless you build that as well. Neither one tells you who was using the machine.

How does a lease stop an EC2 instance?

A lease is a booking of a machine for a set time. In Idlefy, a managed virtual machine (VM) stays stopped until a person leases it for an hour, a workday or longer. The lease starts the machine, which takes about a minute. Warnings go out 20 and 5 minutes before the lease ends, so the person can save or extend. When the lease ends, the machine stops itself, with nobody needing to remember. The person can also release it early. On Pro, a lease can run up to 72 hours, and the Safety System grants one 30-minute grace period if the machine still looks in use at the end of a lease that was not extended. Every lease records who had the machine and until when. Idlefy works with EC2 on AWS and with VMs on Google Cloud.

Which method should you use?

Method Off by default Warns the person Nothing to build
Idlefy lease Yes Yes Yes
Schedule No If you build it No
Low-usage alarm No If you build it No

A lease suits machines people use on and off: development VMs, GPU boxes, test environments. Keep a machine that has to serve customers around the clock out of this model, because a lease is for machines that are only needed while someone is working.

How do you set up automatic stops with Idlefy?

An organization owner connects the cloud account, by default without access keys, then marks the machines to manage:

  1. Connect AWS or Google Cloud in Idlefy.
  2. Tag each VM you want managed with idlefy=enabled.
  3. Give your team or individual people access to those VMs.
  4. People lease a machine from the web dashboard, from Slack or Telegram on paid plans, or through an AI agent.

On AWS the tag boundary is enforced by the IAM policy itself: Idlefy can start, stop and reboot only tagged instances. On Google Cloud a VM joins management only if it carries the label when discovered, which is a check on our side and not a cloud policy. Details are on the how it works page.

What does automatic stopping not cover?

  • A machine you did not tag is not managed, and Idlefy will not stop it.
  • A machine started without a lease has no lease timer, so nothing promises when it stops.
  • A stopped machine still costs its disk.
  • Data on local instance-store drives does not survive a stop. Persistent disks do.
  • A budget can refuse new leases, but it never stops a running one.

How do you find instances that are already running idle?

Run an audit before you change anything. The free Idle Audit reads your connected account and estimates what idle hours cost on standalone machines outside Idlefy’s management. A scan changes nothing in your cloud and takes minutes for most accounts. See also our guide to auditing idle VMs in AWS and GCP.

Frequently asked questions

Does stopping an EC2 instance delete anything? No, stopping keeps the instance and its persistent disks. Data on local instance-store drives is lost.

Does a stopped EC2 instance still cost money? Yes, its disks keep costing their normal rate. Compute billing stops with the machine.

What happens if I am still working when the lease ends? You get warnings 20 and 5 minutes before the end and can extend the lease. If you do nothing, the machine stops.

Can an AI agent lease and stop a machine? Yes, through the MCP server. The agent acts as you, with your role. See Start an EC2 instance from Claude Code.

Will Idlefy touch instances I did not tag? No. Idlefy reads them for the audit and does not start or stop them.

Disclosure

I’m the founder of Idlefy, so this describes our own product and favors it. The lease lifecycle is on the how it works page.


Related reading: The $5,000 weekend on what a forgotten environment costs, and A dev box for AI coding agents on personal machines that Idlefy creates for you.