AWS Elastic Beanstalk - why should I use the leader_only command for the command?

I am writing a django application that I plan to install on AWS through Elastic Beanstalk. I am trying to understand why I need to specify "leader_only" for the container command that I want to run for my application. Learn more about this here .

It says:

Alternatively, you can use leader_only. One instance is selected as the leader in the Auto Scaling group. If set to leader_only true, the command runs only on the instance marked as leader.

If I have several instances on which my application is running because I want to scale it, would not use the "leader_only" command launch on only one instance and would not affect the rest? I probably misunderstand the purpose of this, but it does not seem ideal, because the environment in the leader may differ from other instances, and the end user may receive different results depending on which instance they are connected to.

+8
amazon-web-services elastic-beanstalk
source share
1 answer

From a technical point of view, an elastic bean conductor is an autoscale group, and when you deploy something, you need to assume that your commands can potentially be executed simultaneously in several ec2 instances.

The main goal of leader_only is to make sure that your commands will be executed on only one instance of ec2. This is useful for use: running db migration scripts, creating db, etc., which should only be run once on a single ec2. Thus, leader_only is just a marker that some commands will be executed only in this instance.

However, you need to keep in mind that the leader attribute is set once to create your environment in case the leader died and was replaced by a new situation, when the situation does not arise, if you do not have leaders in the autosave group.

+15
source share

All Articles