title: AWS ElasticBeanstalk Cron Jobs
body: <p>We are using ElasticBeanstalk for our application so that we can have it automatically scale with traffic.  Currently we only have the need for a single cron job to run nightly at 3am and I am trying to get it to work through the use of <code>.ebextensions</code>.</p>
  
  <p>I have the following in a conjob.config file and it is being executed because I can go to the server and <code>cat /etc/cron.d/daily_snapshots</code>.</p>
  
  <pre><code>files:
      "/etc/cron.d/daily_snapshots":
      mode: "000644"
      owner: root
      group: root
      content: |
          * * * * * root /usr/bin/php /var/www/html/artisan schedule:run &gt;&gt; /dev/null 2&gt;&amp;1
  </code></pre>
  
  <p>However, the cronjob is not executing on the schedule that I have set because the database records are not being updated.  I have run the command manually on the EC2 instance and it runs just fine.</p>
  
  <p>We are using Laravel 5.3 so this is how I have the cron scheduled to run.</p>
  
  <pre><code>protected function schedule(Schedule $schedule)
  {
      $schedule-&gt;command('ryno:compile-daily-snapshots')-&gt;dailyAt('03:00')-&gt;sendOutputTo(storage_path().'/logs/cron.log');
  }
  </code></pre>
  
  <p>As stated it will run when I execute the exact same command that is in the cron file but it will not execute automatically when the cron runs.</p>
  
  <p>We currently only have a single instance and I have read today that doing the cronjob in this manner is not a good idea because when another instance is spun up it would execute the cronjob for each EC2 instance in the environment.</p>
  
  <p>I have read that I should use the leader_only setting and set it to true but I have also read that there are issues with that since the leader can change.</p>
  
  <p>I know that I could spin up a worker instance and have that run the cron but with a single cron it seems like a large waste of resources.  </p>
  
  <p>How do you manage your cronjobs on your ElasticBeanstalk environment and which way would you suggest we take for this path?</p>