'AWS ElasticBeanstalk instance protection for leader_only node

I have a django application running on EBS. My application runs celery beat on 1 of the instances by using the ebextension container command:

  03_celery_tasks:
    command: "cat .ebextensions/files/celery_configuration.txt > /opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh && chmod 744 /opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh"
    leader_only: true
  04_celery_tasks_run:
    command: "/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh"
    leader_only: true

During auto-scaling/or routine cleanup EBS might remove the leader_only node which cause celery scheduled task to stop running.

I know there is the ability to protect instances during scale-in/out moments

However I am not sure how to enable instance protection for my leader node specifically (the one running celery beat)

UPDATE

I will try this solution from a certified AWS solution architect: a https://ajbrown.org/2017/02/10/leader-election-with-aws-auto-scaling-groups.html



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source