I have an elastic beanstalk application that utilises both the web tier and the worker tier. Jobs are offloaded onto the worker tier from the web tier via SQS to keep the web-facing servers speedy. Both environments use the exact same codebase, and use an RDS instance under them.
I need to run a cron job on the leader server of the worker tier. I've created a .ebextensions folder with a file called crontab
in it as follows (it's a Laravel web app):
* * * * * root php /var/www/html/artisan do:something:with:database
Then, I've created a file called 01cronjobs.config
, which updates the environments crontab under root as follows:
container_commands:
01_remove_old_cron_jobs:
command: "crontab -r || exit 0"
02_cronjobs:
command: "cat .ebextensions/crontab | crontab"
leader_only: true
.. all good. Now, I want to deploy this to EB using the eb deploy
command. However, I only want the worker tier to take on the cron job, as we can only have one server run the crons throughout the group.
Is there a way to tell the ebextensions config file to only run the config command on the worker tier? Something like worker_only: true
would be great here, but it doesn't seem to exist.
Can anybody provide some insight on how I might achieve this? Thanks.