3

I have deployed my laravel project on AWS Elasticbeanstalk and I have a cronjob task. How do I configure it to run? I have seen multiple answers but either they are no longer valid, too complex or not described well. Any sort of guide/steps I can follow to do that?

In many deployment services there's the cpanel where I would easily configure a cronjob but stating the path where it exists but I can't find anything for that on AWS.

omarsafwany
  • 3,695
  • 8
  • 44
  • 75
  • possible duplicate of [AWS Elastic Beanstalk, running a cronjob](http://stackoverflow.com/questions/14077095/aws-elastic-beanstalk-running-a-cronjob) – tedder42 Jan 29 '15 at 16:39
  • [Scheduled Tasks Without Cron](http://stackoverflow.com/questions/11616205/run-scheduled-task-in-aws-without-cron) might help. – Neha Nov 06 '15 at 13:44

2 Answers2

0

cpanel or even ssh access won't help you here, as Elastic Beanstalk is allowed to replace your server instances as it see fit. This means that if you use cpanel, your changes will be lost in the next time EB decides to spin up a new server.
Now in order to ensure your cron is properly populated, you'd need to use the .ebextensions mechanism. It's a small script that is run when a new server spins up, and can populate your cron.
Here're the steps to introduce such a script:

  1. create a /.ebextensions folder in the root of your project
  2. create the file /.ebextension/populate_cron.config
  3. enter the following text into that file:

container_commands: populate_cron: command: crontab -l | { cat; echo "0 0 0 0 0 your command"; } | crontab - leader_only: true (note that this is a yaml file, so keep the indentation as is)

  1. commit this file and eb deploy
  2. after the env is up, eb ssh to see that the cron is there
Tal
  • 7,827
  • 6
  • 38
  • 61
0

It's a bit late to post the answer but mainly you need to run crontab -e which would open a crontab file. You can then add all your jobs as follows:

* * * * * /path/to/your/command

The 5 * means every minute forever so you need to configure it accordingly. You can check this guide as well.

omarsafwany
  • 3,695
  • 8
  • 44
  • 75