Need help?

Our experts have had an average response time of 11.7 minutes in August 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Cron Jobs on Amazon EC2 Instances in Elastic Beanstalk Environment

by | Jul 10, 2021

We can use Elastic Beanstalk configuration files, .ebextensions, to create cron jobs that run on all Amazon EC2 instances in an Elastic Beanstalk environment.

Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.

Today, let us discuss Cron Jobs on Amazon EC2 Instances.


Cron Jobs on Amazon EC2 Instances in Elastic Beanstalk Environment

In the Elastic Beanstalk application zip file, we need to create a directory named .ebextensions. This will contain configuration files that run when we deploy the application to Amazon EC2 instances.

If we have a periodic task to run on one instance, we can use the cron-leaderonly-linux.config file for web environments.

On the other hand, we need to consider periodic tasks if we use a dedicated worker environment.

Moving ahead, let us see how our Support Techs go about this.


Create or update your configuration file

The two keys in the cron-linux.config file is files and commands.

While the files key specifies the location of the file, the commands key specifies a list of commands to run on the instances.

We can download the cron-linux.config template from the AWS GitHub repository.

Another option is to create or update an existing configuration file.

For example,

mode: "000644"
owner: root
group: root
content: |
* * * * * root /usr/local/bin/

mode: "000755"
owner: root
group: root
content: |

date > /tmp/date
# Your actual script content

exit 0

command: "rm -f /etc/cron.d/mycron.bak"

Make note that multiple configuration files in the .ebextensions directory run in alphabetical order by file name.

So we can name the configuration file cron-linux.config.

This file will create the cron file, /etc/cron.d/mycron. It is configured to run a script every minute.

The script outputs the date and then exits when it runs.

Every time the cron-linux.config apply during deployments, it creates a backup of the /etc/cron.d/mycron file, which is, /etc/cron.d/mycron.bak.

The last command in cron-linux.config cleans up the /etc/cron.d directory by removing /etc/cron.d/mycron.bak.


Create an application source bundle

Our Support Techs recommend these steps to add the configuration file to the application source code of the web application:

  1. In the root of the application folder, we create a directory, .ebextensions.
  2. Then we move the cron-linux.config file to the .ebextensions folder.
  3. In addition, we create a zip folder for the application files, including the new configuration file.

For example, the structure of the .ebextensions directory and cron-linux.config file in the application zip file will be like this:

|-- .ebextensions
| |-- cron-linux.config 
| |-- other .config files
|-- other application files

[Need help with the procedures? Feel free to contact us]



In short, we saw how our Support Techs go about Cron Jobs on Amazon EC2 Instances.


Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.


var google_conversion_label = "owonCMyG5nEQ0aD71QM";


Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.