Issue
Let me know if I understood how auto scaling works.
For example I create a EC2 service with auto scaling (filter, 80% max CPU usage). I run 10 python scripts (that sends lots of python requests per time [amount changes by hours]) on my initial instance. When CPU usage increased more than 80%, AWS starts a new instance.
What is happening now?
- AWS splits 5 scripts per instance?
- AWS splits scripts till first instance is under 80% CPU usage and send other scripts to the other instance (e.g. 7 in the initial instance and 3 in the second one)
- AWS hard copy the initial instance so I got 2 instances with the same scripts running, that are doing the same tasks (e.g. if script A in instance 1 sends an email, also script A in instance 2 sends the same email).
That's my n00b question.
Solution
Amazon EC2 Auto Scaling will automatically launch new instances or terminate existing instances.
What is running on those instances is totally up to you, and must be configured by you. Typically, people configure the instances by either specifying a pre-configured AMI that already contains all the necessary software (eg web server, scripts, etc) OR the instance is launched with a "User Data Script" that runs when the instance boots, and can be used to configure the instance (eg load and start software).
The Auto Scaling service will not provision your scripts, nor rebalance your scripts. Such activities must be managed by you (somehow).
If your scripts are processing information from a data source, a common architectural pattern is:
- Push 'work' (as messages) into an Amazon SQS queue
- Have the scripts on EC2 instance retrieve messages from the queue and perform work
This way, the work will divide amongst the 'compute' instances.
Answered By - John Rotenstein Answer Checked By - Timothy Miller (WPSolving Admin)