I have a server hosted on EC2. The server is built on the Linux AMI, based on CentOS. It is dedicated to a client project, and I connect via SSH. Sometimes, I forget to shut down the server when unused, therefore generating unnecessary costs.
How do I make the server shut down automatically on inactivity, for example after 30 min without an SSH connection?
Naturally, I am looking for the simplest solution. A check every hour or so would also be OK, just something that works reliably.
Best Answer
As of January 2013 Amazon CloudWatch provides an option to Use Amazon CloudWatch to Detect and Shut Down Unused Amazon EC2 Instances, see the introductory blog post Amazon CloudWatch - Alarm Actions for details on this functionality:
Your use case is listed in section Failsafe Ideas specifically:
As outlined, this depends on being able to heuristically detect the appropriate condition triggering the alarm and stopping the instance - you might take it to the next level by means of Publishing Custom Metrics to CloudWatch based on the logged in SSH user count, idle time or else and gain more control/precision for the desired detection and shutdown process in turn.