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.
Worker environments run a daemon process provided by Elastic Beanstalk. This daemon is updated regularly to add features and fix bugs. To get the latest version of the daemon, update to the latest platform version.
In AWS Elastic Beanstalk, you can create a load-balanced, scalable environment or a single-instance environment. The type of environment that you require depends on the application that you deploy.
Sample from the AWS doc:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
commands:
python_install:
command: myscript.py
cwd: /home/ec2-user
env:
myvarname: myvarvalue
test: '[ ! /usr/bin/python ] && echo "python not installed"'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With