Search code examples
pythondjangoamazon-web-servicescronamazon-elastic-beanstalk

Cron job with elastic beanstalk and django


I'm working on implementing some cronjobs with my application running on elastic beanstalk but am unsure of how to proceed. My current cron-linux.config file in the .ebextension folder looks like:

files:
  "/etc/cron.d/mycron":
    mode: "000644"
    owner: root
    group: root
    content: |
      * * * * * root /usr/bin/python opt/python/current/app/api/cron.py > /dev/null

commands:
  remove_old_cron:
    command: "rm -f /etc/cron.d/*.bak"

I've used eb ssh to make sure that the paths point to the correct location. The problem is that I'm not getting any error messages so it's quite hard to know where the problem is. Any help would be much appreciated!


Solution

  • You are supressing your outputs.

    Try replacing the schedule line from:

    * * * * * root /usr/bin/python opt/python/current/app/api/cron.py > /dev/null
    

    To:

    * * * * * root /usr/bin/python opt/python/current/app/api/cron.py > /home/<USER>/logs/backup.log 2>&1
    

    You should be able to see the logs in /home/<USER>/logs/backup.log. Make sure that your script is outputing messages, success or error.