Currently, we have a single production server running on an EC2 instance. Since we are getting a lot of traffic, we would like to use the Autoscaling feature, but we are kind of new to this.
Following is my understanding:
- We create a custom AMI from our existing production server
- Create a launch configuration from this AMI
- Create an AutoScaling group with this launch configuration
- Set conditions, if CPU usage is greater than 60%, add an instance, if less than 40% terminate 1 instance.
- Add a load balancer to this autoscaling group
- Now as far as I understood, to deploy new code to the auto scaling group, we have to create a new AMI with our updated application version and change the AMI used in the autoscaling group to this new one. Then terminate all the previous instances and create new ones from the updated AMI.
1. To create the updated AMI, do I have to keep our previous EC2 instance that is not part of the auto scaling group?
Deploy the new code there and create an AMI from that instance?
2. Or instead of creating new AMIs, we could just ssh into every server and pull new code from there? but the new instance that would spawn would be using the previous code.
3. Also, after adding the new AMI, how do we properly terminate all the previous instances?
4. Finally, How do we properly automate this?