PHPackages                             dusterio/laravel-aws-worker - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. dusterio/laravel-aws-worker

ActiveLibrary[Queues &amp; Workers](/categories/queues)

dusterio/laravel-aws-worker
===========================

Run Laravel (or Lumen) tasks and queue listeners inside of AWS Elastic Beanstalk workers

v1.0.04(1y ago)3105.7M—9.4%59[1 issues](https://github.com/dusterio/laravel-aws-worker/issues)[1 PRs](https://github.com/dusterio/laravel-aws-worker/pulls)MITPHPPHP &gt;=5.5.0CI failing

Since Jun 2Pushed 1y ago14 watchersCompare

[ Source](https://github.com/dusterio/laravel-aws-worker)[ Packagist](https://packagist.org/packages/dusterio/laravel-aws-worker)[ Docs](https://github.com/dusterio/laravel-aws-worker)[ RSS](/packages/dusterio-laravel-aws-worker/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (47)Used By (0)

laravel-aws-worker
==================

[](#laravel-aws-worker)

[![Code Climate](https://camo.githubusercontent.com/f6185429fa46bd204a3bf84c670565387f422a6ff1154b3615ec4933c8ae6d0d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f647573746572696f2f6c61726176656c2d6177732d776f726b65722f6261646765732f6770612e737667)](https://codeclimate.com/github/dusterio/laravel-aws-worker/badges)[![Total Downloads](https://camo.githubusercontent.com/e78b53c6da662edb608fc1742b08eb66ab8c2846ec77dd1168ab08808592a32d/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c61726176656c2d6177732d776f726b65722f642f746f74616c2e737667)](https://packagist.org/packages/dusterio/laravel-aws-worker)[![Latest Stable Version](https://camo.githubusercontent.com/a3e7290e6cfe6155c63aef1ffe90aea9cf0a5194a31096e27dc2997d61320c6d/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c61726176656c2d6177732d776f726b65722f762f737461626c652e737667)](https://packagist.org/packages/dusterio/laravel-aws-worker)[![Latest Unstable Version](https://camo.githubusercontent.com/9e93cd55f3bf5e65e593465c5f3b9582a01fdf04a2033a7b1ecd4177fc83d680/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c61726176656c2d6177732d776f726b65722f762f756e737461626c652e737667)](https://packagist.org/packages/dusterio/laravel-aws-worker)[![License](https://camo.githubusercontent.com/138af506dc1b3c1f1f56f9955965915b12aecfa5725ea002ce5b3bfea8872092/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c61726176656c2d6177732d776f726b65722f6c6963656e73652e737667)](https://packagist.org/packages/dusterio/laravel-plain-sqs)

Run Laravel tasks and queue listeners inside of AWS Elastic Beanstalk workers

> We've dropped future support for Lumen, however you can still use [v0.1.40](https://github.com/dusterio/laravel-aws-worker/releases/tag/v0.1.40) for Lumen.

Overview
--------

[](#overview)

Laravel documentation recommends to use supervisor for queue workers and \*IX cron for scheduled tasks. However, when deploying your application to AWS Elastic Beanstalk, neither option is available.

This package helps you run your Laravel jobs in AWS worker environments.

[![Standard Laravel queue flow](https://camo.githubusercontent.com/aea87bfa491761beaef02db7618003634898488e8144b0980dde967baa64b0c8/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f7175657565732d6c61726176656c2e706e67)](https://camo.githubusercontent.com/aea87bfa491761beaef02db7618003634898488e8144b0980dde967baa64b0c8/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f7175657565732d6c61726176656c2e706e67)[![AWS Elastic Beanstalk flow](https://camo.githubusercontent.com/311527190b2cb59c8c90551ae7d17633bd4f484aa8d92f1c00588105f6f7d8b3/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f7175657565732d6177735f65622e706e67)](https://camo.githubusercontent.com/311527190b2cb59c8c90551ae7d17633bd4f484aa8d92f1c00588105f6f7d8b3/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f7175657565732d6177735f65622e706e67)

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.5
- Laravel &gt;= 5.1

Scheduled tasks - option 1
--------------------------

[](#scheduled-tasks---option-1)

Option one is to use Kernel.php as the schedule and run Laravel schedule runner every minute. You remember how Laravel documentation advised you to invoke the task scheduler? Right, by running `php artisan schedule:run` on regular basis, and to do that we had to add an entry to our cron file:

```
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
```

AWS doesn't allow you to run \*IX commands or to add cron tasks directly. Instead, you have to make regular HTTP (POST, to be precise) requests to your worker endpoint.

Add cron.yaml to the root folder of your application (this can be a part of your repo or you could add this file right before deploying to EB - the important thing is that this file is present at the time of deployment):

```
version: 1
cron:
 - name: "schedule"
   url: "/worker/schedule"
   schedule: "* * * * *"
```

From now on, AWS will do POST /worker/schedule to your endpoint every minute - kind of the same effect we achieved when editing a UNIX cron file. The important difference here is that the worker environment still has to run a web process in order to execute scheduled tasks. Behind the scenes it will do something very similar to a built-in `schedule:run` command.

Your scheduled tasks should be defined in `App\Console\Kernel::class` - just where they normally live in Laravel, eg.:

```
protected function schedule(Schedule $schedule)
{
    $schedule->command('inspire')
              ->everyMinute();
}
```

Scheduled tasks - option 2
--------------------------

[](#scheduled-tasks---option-2)

Option two is to use AWS schedule defined in the cron.yml:

```
version: 1
cron:
 - name: "run:command"
   url: "/worker/schedule"
   schedule: "0 * * * *"

 - name: "do:something --param=1 -v"
   url: "/worker/schedule"
   schedule: "*/5 * * * *"
```

Note that AWS will use UTC timezone for cron expressions. With the above example, AWS will hit /worker/schedule endpoint every hour with `run:command` artisan command and every 5 minutes with `do:something` command. Command parameters aren't supported at this stage.

Pick whichever option is better for you!

Queued jobs: SQS
----------------

[](#queued-jobs-sqs)

Normally Laravel has to poll SQS for new messages, but in case of AWS Elastic Beanstalk messages will come to us – inside of POST requests from the AWS daemon.

Therefore, we will create jobs manually based on SQS payload that arrived, and pass that job to the framework's default worker. From this point, the job will be processed the way it's normally processed in Laravel. If it's processed successfully, our controller will return a 200 HTTP status and AWS daemon will delete the job from the queue. Again, we don't need to poll for jobs and we don't need to delete jobs - that's done by AWS in this case.

If you dispatch jobs from another instance of Laravel or if you are following Laravel's payload format `{"job":"","data":""}` you should be okay to go. If you want to receive custom format JSON messages, you may want to install [Laravel plain SQS](https://github.com/dusterio/laravel-plain-sqs) package as well.

Configuring the queue
---------------------

[](#configuring-the-queue)

Every time you create a worker environment in AWS, you are forced to choose two SQS queues – either automatically generated ones or some of your existing queues. One of the queues will be for the jobs themselves, another one is for failed jobs – AWS calls this queue a dead letter queue.

You can set your worker queues either during the environment launch or anytime later in the settings:

[![AWS Worker queue settings](https://camo.githubusercontent.com/553d012c12241183043816d94248d8dfb0e034891268416e04568302a28b5aa7/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f776f726b65725f73657474696e67732e6a7067)](https://camo.githubusercontent.com/553d012c12241183043816d94248d8dfb0e034891268416e04568302a28b5aa7/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f776f726b65725f73657474696e67732e6a7067)

Don't forget to set the HTTP path to `/worker/queue` – this is where AWS will hit our application. If you chose to generate queues automatically, you can see their details later in SQS section of the AWS console:

[![AWS SQS details](https://camo.githubusercontent.com/171f0cef63ff19b6775eb274cd7af6547b3036df257617cc53182e416e5434c3/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f7371735f64657461696c732e6a7067)](https://camo.githubusercontent.com/171f0cef63ff19b6775eb274cd7af6547b3036df257617cc53182e416e5434c3/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f7371735f64657461696c732e6a7067)

You have to tell Laravel about this queue. First set your queue driver to SQS in `.env` file:

```
QUEUE_DRIVER=sqs

```

Then go to `config/queue.php` and copy/paste details from AWS console:

```
        ...
        'sqs' => [
            'driver' => 'sqs',
            'key' => 'your-public-key',
            'secret' => 'your-secret-key',
            'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
            'queue' => 'your-queue-name',
            'region' => 'us-east-1',
        ],
        ...
```

To generate key and secret go to Identity and Access Management in the AWS console. It's better to create a separate user that ONLY has access to SQS.

Installation via Composer
-------------------------

[](#installation-via-composer)

To install simply run:

```
composer require dusterio/laravel-aws-worker

```

Or add it to `composer.json` manually:

```
{
    "require": {
        "dusterio/laravel-aws-worker": "~0.1"
    }
}
```

### Usage in Laravel 5

[](#usage-in-laravel-5)

```
// Add in your config/app.php

'providers' => [
    '...',
    'Dusterio\AwsWorker\Integrations\LaravelServiceProvider',
];
```

After adding service provider, you should be able to see two special routes that we added:

```
$ php artisan route:list
+--------+----------+-----------------+------+----------------------------------------------------------+------------+
| Domain | Method   | URI             | Name | Action                                                   | Middleware |
+--------+----------+-----------------+------+----------------------------------------------------------+------------+
|        | POST     | worker/queue    |      | Dusterio\AwsWorker\Controllers\WorkerController@queue    |            |
|        | POST     | worker/schedule |      | Dusterio\AwsWorker\Controllers\WorkerController@schedule |            |
+--------+----------+-----------------+------+----------------------------------------------------------+------------+
```

Environment variable `REGISTER_WORKER_ROUTES` is used to trigger binding of the two routes above. If you run the same application in both web and worker environments, don't forget to set `REGISTER_WORKER_ROUTES` to `false` in your web environment. You don't want your regular users to be able to invoke scheduler or queue worker.

This variable is set to `true` by default at this moment.

So that's it - if you (or AWS) hits `/worker/queue`, Laravel will process one queue item (supplied in the POST). And if you hit `/worker/schedule`, we will run the scheduler (it's the same as to run `php artisan schedule:run` in shell).

### Usage in Lumen 5

[](#usage-in-lumen-5)

```
// Add in your bootstrap/app.php
$app->register(Dusterio\AwsWorker\Integrations\LumenServiceProvider::class);
```

Errors and exceptions
---------------------

[](#errors-and-exceptions)

Please make sure that two special routes are not mounted behind a CSRF middleware. Our POSTs are not real web forms and CSRF is not necessary here. If you have a global CSRF middleware, add these routes to exceptions, or otherwise apply CSRF to specific routes or route groups.

If your job fails, we will throw a `FailedJobException`. If you want to customize error output – just customise your exception handler. Note that your HTTP status code must be different from 200 in order for AWS to realize the job has failed.

Job expiration (retention)
--------------------------

[](#job-expiration-retention)

A new nice feature is being able to set a job expiration (retention in AWS terms) in seconds so that low value jobs get skipped completely if there is temporary queue latency due to load.

Let's say we have a spike in queued jobs and some of them don't even make sense anymore now that a few minutes passed – we don't want to spend computing resources processing them later.

By setting a special property on a job or a listener class:

```
class PurgeCache implements ShouldQueue
{
    public static int $retention = 300; // If this job is delayed more than 300 seconds, skip it
}
```

We can make sure that we won't run this job later than 300 seconds since it's been queued. This is similar to AWS SQS "message retention" setting which can only be set globally for the whole queue.

To use this new feature, you have to use provided `Jobs\CallQueuedHandler` class that extends Laravel's default `CallQueuedHandler`. A special `ExpiredJobException` exception will be thrown when expired jobs arrive and then it's up to you what to do with them.

If you just catch these exceptions and therefore stop Laravel from returning code 500 to AWS daemon, the job will be deleted by AWS automatically.

ToDo
----

[](#todo)

1. Add support for AWS dead letter queue (retry jobs from that queue?)

Video tutorials
---------------

[](#video-tutorials)

I've just started a educational YouTube channel that will cover top IT trends in software development and DevOps: [config.sys](https://www.youtube.com/channel/UCIvUJ1iVRjJP_xL0CD7cMpg)

Also I'm glad to announce a new cool tool of mine – [GrammarCI](https://www.grammarci.com/), an automated typo/grammar checker for developers, as a part of the CI/CD pipeline.

Implications
------------

[](#implications)

Note that AWS cron doesn't promise 100% time accuracy. Since cron tasks share the same queue with other jobs, your scheduled tasks may be processed later than expected.

Post scriptum
-------------

[](#post-scriptum)

I wrote a [blog post](https://web.archive.org/web/20210616063916/https://blog.menara.com.au/2016/06/running-laravel-in-amazon-elastic-beanstalk/) explaining how this actually works.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance46

Moderate activity, may be stable

Popularity63

Solid adoption and visibility

Community28

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 53.3% of commits — single point of failure

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 ~71 days

Recently: every ~93 days

Total

46

Last Release

417d ago

Major Versions

v0.1.40 → v1.0.002024-03-20

### Community

Maintainers

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

---

Top Contributors

[![dusterio](https://avatars.githubusercontent.com/u/11039918?v=4)](https://github.com/dusterio "dusterio (49 commits)")[![timmylindh](https://avatars.githubusercontent.com/u/74464421?v=4)](https://github.com/timmylindh "timmylindh (10 commits)")[![fylzero](https://avatars.githubusercontent.com/u/3542501?v=4)](https://github.com/fylzero "fylzero (10 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")[![mccahan](https://avatars.githubusercontent.com/u/2308923?v=4)](https://github.com/mccahan "mccahan (3 commits)")[![d3radicated](https://avatars.githubusercontent.com/u/22888549?v=4)](https://github.com/d3radicated "d3radicated (3 commits)")[![altin7m](https://avatars.githubusercontent.com/u/24477391?v=4)](https://github.com/altin7m "altin7m (2 commits)")[![cyberduckneil](https://avatars.githubusercontent.com/u/90324469?v=4)](https://github.com/cyberduckneil "cyberduckneil (2 commits)")[![pushpak](https://avatars.githubusercontent.com/u/2714784?v=4)](https://github.com/pushpak "pushpak (2 commits)")[![gilbitron](https://avatars.githubusercontent.com/u/203882?v=4)](https://github.com/gilbitron "gilbitron (1 commits)")[![gcg](https://avatars.githubusercontent.com/u/811685?v=4)](https://github.com/gcg "gcg (1 commits)")[![nadge](https://avatars.githubusercontent.com/u/3862793?v=4)](https://github.com/nadge "nadge (1 commits)")[![organiseio](https://avatars.githubusercontent.com/u/20773101?v=4)](https://github.com/organiseio "organiseio (1 commits)")[![dclaysmith](https://avatars.githubusercontent.com/u/226740?v=4)](https://github.com/dclaysmith "dclaysmith (1 commits)")[![Sensetivity](https://avatars.githubusercontent.com/u/4289543?v=4)](https://github.com/Sensetivity "Sensetivity (1 commits)")[![gtlkirit](https://avatars.githubusercontent.com/u/17121399?v=4)](https://github.com/gtlkirit "gtlkirit (1 commits)")

---

Tags

awsbeanstalklaravelworkerphplaravelawslumensqselasticbeanstalkworker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dusterio-laravel-aws-worker/health.svg)

```
[![Health](https://phpackages.com/badges/dusterio-laravel-aws-worker/health.svg)](https://phpackages.com/packages/dusterio-laravel-aws-worker)
```

###  Alternatives

[dusterio/laravel-plain-sqs

Custom SQS connector for Laravel that supports custom format JSON

1352.7M1](/packages/dusterio-laravel-plain-sqs)[shiftonelabs/laravel-sqs-fifo-queue

Adds a Laravel queue driver for Amazon SQS FIFO queues.

1556.0M3](/packages/shiftonelabs-laravel-sqs-fifo-queue)[joblocal/laravel-sqs-sns-subscription-queue

A simple Laravel service provider which adds a new queue connector to handle SNS subscription queues.

48416.3k](/packages/joblocal-laravel-sqs-sns-subscription-queue)

PHPackages © 2026

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