PHPackages                             foxxmd/laravel-elasticbeanstalk-cron - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. foxxmd/laravel-elasticbeanstalk-cron

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

foxxmd/laravel-elasticbeanstalk-cron
====================================

Ensure only one Laravel instance is running CRON jobs in an EB environment

2.1.0(2mo ago)62311.8k↓27.8%17[1 issues](https://github.com/FoxxMD/laravel-elasticbeanstalk-cron/issues)MITPHP

Since Sep 28Pushed 2mo ago8 watchersCompare

[ Source](https://github.com/FoxxMD/laravel-elasticbeanstalk-cron)[ Packagist](https://packagist.org/packages/foxxmd/laravel-elasticbeanstalk-cron)[ RSS](/packages/foxxmd-laravel-elasticbeanstalk-cron/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (10)Dependencies (8)Versions (16)Used By (0)

Laravel 6 - 13.x Task Scheduler with Elastic Beanstalk
======================================================

[](#laravel-6---13x-task-scheduler-with-elastic-beanstalk)

*Ensure one instance in an Elastic Beanstalk environment is running Laravel's Scheduler*

A common [problem](https://stackoverflow.com/questions/14077095/aws-elastic-beanstalk-running-a-cronjob) [many](http://culttt.com/2016/02/08/setting-up-and-using-cron-jobs-with-laravel-and-aws-elastic-beanstalk/) [people](https://medium.com/@joelennon/running-cron-jobs-on-amazon-web-services-aws-elastic-beanstalk-a41d91d1c571#.i53d41sci) have encountered with Amazon's [Elastic Beanstalk](https://aws.amazon.com/elasticbeanstalk/) is maintaining a single instance in an environment that runs Laravel's Task Scheduler. Difficulties arise because auto-scaling does not guarantee any instance is run indefinitely and there are no "master-slave" relationships within an environment to differentiate one instance from the rest.

Although Amazon has provided a [solution](http://stackoverflow.com/a/28719447/1469797) it involves setting up a worker tier and then, potentially, creating new routes/methods for implementing the tasks that need to be run. Yuck!

**This package provides a simple, zero-setup solution for maintaining one instance within an Elastic Beanstalk environment that runs the Task Scheduler.**

Amazon Linux 1 and Amazon Linux 2 are deprecated — Amazon Linux 2023 is required
--------------------------------------------------------------------------------

[](#amazon-linux-1-and-amazon-linux-2-are-deprecated--amazon-linux-2023-is-required)

Amazon Linux 1 (AL1) is retired and Amazon Linux 2 (AL2) PHP platforms were removed from Elastic Beanstalk on April 16, 2026. You must use Amazon Linux 2023 (AL2023).

This release only supports AL2023. Please use previous releases for AL2.

How Does It Work?
-----------------

[](#how-does-it-work)

Glad you asked! The below process **is completely automated** and only requires that you publish the `.platform` folder to the root of your application.

### 1. Use Elastic Beanstalk's Advanced Configuration to run CRON setup commands

[](#1-use-elastic-beanstalks-advanced-configuration-to-run-cron-setup-commands)

EB applications since AL2 can contain [platform hooks](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html) that provides advanced configuration for an EB environment, called `.platform`.

This package provides a configuration file that runs two commands on deployment (every instance initialization) that setup the conditions needed to run the Task Scheduler on one instance:

### 2. Run `system:start:leaderselection`

[](#2-run-systemstartleaderselection)

This is the first command that is run on deployment. It configures the instance's Cron to run **Leader Selection** at a configured interval (default = 5 minutes)

### 3. Run **Leader Selection** `aws:configure:leader`

[](#3-run-leader-selection-awsconfigureleader)

This is the **Leader Selection** command. It does the following:

- Get the Id of the Instance this deployment is running on
- Get the `EnvironmentName` of this Instance. (When running in an EB environment all EC2 instances have the same `EnvironmentName`)
- Get all running EC2 instances with that `EnvironmentName`
- Find the **earliest launched instance**

If this instance is the earliest launched then it is deemed the **Leader** and runs `system:start:cron`

### 4. Run `system:start:cron`

[](#4-run-systemstartcron)

This command is run **only if the current instance running Leader Selection is the Leader**. It inserts another entry in the instance's Cron to run [Laravel's Scheduler](https://laravel.com/docs/13.x/scheduling).

### That's it!

[](#thats-it)

Now only one instance, the earliest launched, will have the scheduler inserted into its Cron. If that instance is terminated by auto-scaling a new Leader will be chosen within 5 minutes (or the configured interval) from the remaining running instances.

Installation
------------

[](#installation)

Require this package

```
composer require "foxxmd/laravel-elasticbeanstalk-cron"
```

Then, publish the **.platform** folder and configuration file

```
php artisan vendor:publish --tag=ebcron
```

Don't forget to add +x permission to the EB Platform Hooks scripts ([no longer required for Amazon Linux platform that released on or after April 29, 2022](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.hooks.html#platforms-linux-extend.hooks.more))

```
find .platform -type f -iname "*.sh" -exec chmod +x {} +
```

Configuration
-------------

[](#configuration)

In order for Leader Selection to run a few environmental variables must be present:

- **USE\_CRON** = true -- Must be set in order for Leader Selection to occur. (This can be used to prevent Selection from occurring on undesired environments IE Workers, etc.)

These can be included in your **.env** or, for EB, in the environment's configuration section.

Package uses the EC2 instance profile for credentials. Region is resolved from the `AWS_REGION` environment variable if set, otherwise it is auto-detected from EC2 instance metadata (IMDS).

### IAM Permissions

[](#iam-permissions)

The EC2 instance profile must have `ec2:DescribeInstances` permission for leader selection to work. Add the following inline policy to your EB instance role:

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "ec2:DescribeInstances",
            "Resource": "*"
        }
    ]
}
```

Contributing
------------

[](#contributing)

Make a PR for some extra functionality and I will happily accept it :)

License
-------

[](#license)

This package is licensed under the [MIT license](https://github.com/FoxxMD/laravel-elasticbeanstalk-cron/blob/master/LICENSE.txt).

###  Health Score

61

—

FairBetter than 98% of packages

Maintenance88

Actively maintained with recent releases

Popularity49

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~250 days

Recently: every ~419 days

Total

15

Last Release

61d ago

Major Versions

0.9 → 1.02021-08-19

1.3 → 2.0.02025-03-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/e034a2b4c63a810f72067441ec19dce7d9993a7fad0f1b27dd5734a4a2ad8070?d=identicon)[FoxxMD](/maintainers/FoxxMD)

---

Top Contributors

[![MbahDjoe](https://avatars.githubusercontent.com/u/2148158?v=4)](https://github.com/MbahDjoe "MbahDjoe (20 commits)")[![FoxxMD](https://avatars.githubusercontent.com/u/4663766?v=4)](https://github.com/FoxxMD "FoxxMD (11 commits)")[![jhagel](https://avatars.githubusercontent.com/u/11066431?v=4)](https://github.com/jhagel "jhagel (7 commits)")[![Jono20201](https://avatars.githubusercontent.com/u/2374192?v=4)](https://github.com/Jono20201 "Jono20201 (6 commits)")[![heathdutton](https://avatars.githubusercontent.com/u/302215?v=4)](https://github.com/heathdutton "heathdutton (5 commits)")[![MichaelHoughton](https://avatars.githubusercontent.com/u/5341149?v=4)](https://github.com/MichaelHoughton "MichaelHoughton (3 commits)")[![hugoboss17](https://avatars.githubusercontent.com/u/10523100?v=4)](https://github.com/hugoboss17 "hugoboss17 (1 commits)")

---

Tags

awscroneb-environmentelasticbeanstalklaravellaravel-scheduler

### Embed Badge

![Health badge](/badges/foxxmd-laravel-elasticbeanstalk-cron/health.svg)

```
[![Health](https://phpackages.com/badges/foxxmd-laravel-elasticbeanstalk-cron/health.svg)](https://phpackages.com/packages/foxxmd-laravel-elasticbeanstalk-cron)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M201](/packages/laravel-ai)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

725173.2k14](/packages/tallstackui-tallstackui)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

198321.1k](/packages/fumeapp-modeltyper)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
