Search code examples
amazon-web-servicesamazon-ec2amazon-elastic-beanstalkautoscaling

AWS Auto Scaling: can I stop server by setting 0 for desired, minimum and maximum instances?


I have used AWS Auto Scaling to set up for my web server. My setting config is 1 for desired, minimum and maximum instances.

Now I want to stop my server, but i may want to restart it in future.

But if I stop directly in EC2 dashboard, it will respawn another EC2 instance, due to AWS Auto Scaling config.

So can I stop my server by setting 0 for desired, minimum and maximum instances ?

I know setting desired instance as 0 will terminate my current instance now, but in this case, if I change desired instance to 1 in future(it will initialize a new instance), can new instance will be initialized with last state when terminated, or it will be initialized with state of setting AMI ?


Solution

  • If your auto scaler is set up through Elastic Beanstalk, then you can scale your instances down to 0 through the configuration:

    1. Go to Configuration -> Click Edit under the "Instance traffic and scaling" section
    2. Scroll down to the "Time-based scaling" section
    3. Click "Add scheduled action"
    4. Give a name to your action, it can be anything
    5. Enter 0 for Min, Max, and Desired capacity
    6. Enter a time for the scaling down to occur. It takes a few minutes for the environment to update with the change, so I always set the time at least 10 or 15 minutes into the future if I want it applied right away.
    7. Click "Add"
    8. Scroll down and click "Apply"

    At the specified time, your instances will be scaled down to 0. Go through similar steps to scale your instances back up.