If you have have an autoscaling group, how do you go about start/stopping the instances (not launch/terminate) ? The default behaviour is only for launching and terminating instances, but since we also get cost savings for just stopping an instance, we would rather allow the instance to persist.
For our purposes, we have a QA environment and we want to start/stop several autoscaling groups daily to save money when the development team leaves the office for evenings and weekends.
So how to accomplish this?
NOTE:
I will be following up with my own detailed answer shortly.
You may consider to run your script using AWS Data Pipeline.
Use this script to retrieve instance ID as well as availability zone and region, etc
Choose Create New Pipeline and enter the following information:
Configure each pipeline with appropriate scheduling information.
Set the following options for implementing appropriate security access:
Note that Data Pipeline creates the necessary IAM Roles for you.
For more information, see AWS Data Pipeline Pricing.
See also other option using AWS Lambda.
First and foremost, the AWS autoscaling group is a container for multiple instances that are based on a launch configuration. If we are able to disable the processes that trigger up/down scaling, we are back to the container that just holds instances.
In order to disable these processes, we need to use the
suspend-processes
command from AWS-CLI. For this example, I will usepowershell
, but its just as easy to write inbash
:For my purposes, I wanted the instances to be online between 7am and 7pm to reduce costs. These instances are used between our development and QA teams, and they prefer to keep the state of the server from day to day.
NOTE: in the circumstance where the EC2 instance becomes corrupt or accidentally terminated, our team is fine with rollbacking back to the latest AMI (they really just want the logs to persist, but if they are lost, it isn't the end of the world)
Next we'll require a script to start/stop the servers, here I have it as 2 scripts, but you can easily optimize it into one script and pass an argument in:
The last step would be to add it to the Scheduled Tasks on a control server (I'm currently just using my desktop which never turns off). Attached is an example of the exported Schedule Task, runs weekly Mon, Tue, Wed, Thurs, Friday at 7am.
You'll need to make the "Stop" version of this task to stop servers at 7pm. Just change your start boundary to
<StartBoundary>2014-08-22T19:00:00</StartBoundary>
and update<Arguments>-ExecutionPolicy ByPass c:\tasks\AWS-Autoscaling-EC2-Start-Morning.ps1</Arguments>
to the correctps1
.