I am looking to implement Autoscaling for my website using AWS Autoscaling,
As the first step, I have created an AWS Launching Template (AMI) based on the current EC2 instance, and i am using it as a scale base.
My question is when the Autoscaling kicks in and duplicate the Instances, it seems to be duplicating Cronjobs as well, i.e. making it sending duplicated emails ..etc,
In this type of Scenario what the most simplest way to manage the Cronjobs in an AutoScaling environment ?
Note: I did shutdown the crond service but when the instance start it seems to be active again and some of my own custom services are not on in scaled instances, so bit confused how to handle this situation.
CodePudding user response:
An autoscaling group creates instances from the same AMI, which means that all instances will be identical to each other. This implies that the cron jobs that you have defined in the AMI will run on all instances.
If you don't want the cron jobs to be running on all servers, then you have two options:
Create a separate, standalone EC2 instance from the AMI you've prepared (this instance will be running the cron jobs), and create a separate AMI without the cron jobs to be used by the autoscaling group.
Remove the cron job functionality from the AMI and implement a serverless solution