Last Updated: March 07, 2018
·
331
· coconup

Rails 5.1 + Whenever gem + AWS Elastic Beanstalk - config file for 2018

Ok so as many others did before me, I just spent way too long trying to get the whenever CLI to work within my Rails application, when deployed on AWS through Elastic Beanstalk.

This is the content of the file which FINALLY did it for me. Create it under .ebextensions/whenever.config (or whatever other name .config) within your app's root folder and make sure it's correctly indented (2 spaces per level), as it will be interpreted as YAML:

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/update_cron_tab.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/sh
      EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
      EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
      EB_APP_CURRENT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
      . $EB_SUPPORT_DIR/envvars
      . $EB_SCRIPT_DIR/use-app-ruby.sh

      sudo su - ec2-user -c "cd $EB_APP_CURRENT_DIR; whenever --update-crontab"
      sudo su - ec2-user -c "crontab -l"

PS: I am using the Puma + Ruby 2.5 EB platform v2.7.1