Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to STOP not TERMINATE instances using auto-scaling in AWS?

Tags:

I am looking at using AWS auto-scaling to scale my infrastructure up and down based on various performance metrics (CPU, etc.). I understand how to set this up; however, I don't like that instances are terminated rather than stopped when it is scaled down. This means that when I scale back up, I have to start from scratch with a new instance and re-install my software, etc. I'd rather just start/stop my instances as needed rather than create/terminate. Is there a way to do this?

like image 438
timsterc Avatar asked May 27 '15 21:05

timsterc


People also ask

How do you stop an EC2 instance in Auto Scaling group?

To disable a scaling policy (console)Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ , and choose Auto Scaling Groups from the navigation pane. Select the check box next to the Auto Scaling group. A split pane opens up in the bottom of the Auto Scaling groups page.

How do I turn off AWS termination protection?

Select the instance, and choose Actions, Instance Settings, Change Termination Protection. Choose Yes, Disable.


1 Answers

No, it is not possible to Stop an instance under Auto Scaling. When a Scaling Policy triggers the removal of an instance, Auto Scaling will always Terminate the instance.

However, here's some ideas to cope with the concept of Termination...

Option 1: Use pre-configured AMIs

You can configure an Amazon EC2 instance with your desired software, data and settings. Then, select the EC2 instance in the Management Console and choose the Create Image action. This will create a new Amazon Machine Image (AMI). You can then configure Auto Scaling to use this AMI when launching a new instance. Each new instance will contain exactly the same disk contents.

It's worth mentioning that EBS starts up very quickly from an AMI. Instead of copying the whole AMI to the boot disk, it copies it across on "first access". This means the new instance can start-up immediately rather than waiting for the whole disk to be copied.

Option 2: Use a startup (User Data) script

Each Amazon EC2 instance has a User Data field, which is accessible from the instance. A script can be passed through the User Data field, which is then executed when the instance starts. The script could be used to install software, download data and configure the instance.

The script could do something very simple, like download a configuration script from a source code repository, then execute the script. This means that machine configuration can be centrally managed and version-controlled. Want to update your app? Just launch a new instance with the updated script and throw away the old instance (which is much easier than "updating" an app).

Option 3: Add/Remove instances to an Auto Scaling group

Rather than using Scaling Policies to Launch/Terminate instances for an Auto Scaling group, it is possible to attach/detach specific instances. Thus, you could 'simulate' auto scaling:

  • When you want to scale-down, detach an instance from the Auto Scaling group, then stop it.
  • When you want to add an instance, start the instance then attach it to the Auto Scaling group.

This would require your own code, but it is very simple (basically two API calls). You would be responsible for keeping track of which instance to attach/detach.

like image 98
John Rotenstein Avatar answered Dec 15 '22 12:12

John Rotenstein