Reputation: 4877
I have to set up an AWS instance for a web application that is being used sporadically, a few hours at a time, a few times per month. The application requires a sizeable instance in terms of virtual cpus and memory, so keeping it running 24/7 would run up a steep bill, and since the time it is being used is below ~5% I am looking for a way to automatically suspend the instance if CPU utilization drops below 10% for >2 hours (for example). Also, ideally (but not strictly required) a request to the application's URL would start the instance if it is suspended.
Is there a recommended or more standard way to achieve this?
Upvotes: 1
Views: 720
Reputation: 269410
You could have a script running on the instance that continually measures "usage". (The actual definition of this is up to you — it might be based on app usage, or CPU, or however you want to define it.)
Once the script determines that the instance is not being used, is can simply issue an operating system Shutdown command. If the instance Shutdown Behavior = Stop
, then the instance will gracefully shutdown and stop.
You could then use your 'wake-up' process to Start the instance again.
Upvotes: 1
Reputation: 1719
You can create auto scale group that starting with 1 instance behind Elastic LB. When there is a load with given parameter ( such as cpu load, ram usage , network traffic etc ), the new instance automatically created. When the load is down, it will close the instance automatically too. There is no need to use lambda ;)
Upvotes: 0