Configure Your Laravel Queues with AWS SQS
In this brand new tutorial i am going to show you laravel sqs example. I am working on a Laravel application and somedays ago, I had to migrate my one client project queue driver on a project from Redis to SQS.
In internet there is no related article like Laravel AWS SQS configure and setup. I'm writing this article. If you don't know about how to setup and configure laravel queue with asw sqs then this example tutorial is for you. I will show you step by step guide so that you can understand it clearly. So let's see laravel sqs config example and steps. You have to maintain some steps to complete it like below:
- Your existing Laravel application
- Your AWS account
- Clear understanding of Laravel queues
- Some bit of AWS knowledge
Step 1: Install AWS sdk
In this step we have to install aws sdk via composer command. So run the following command to install the SDK:
composer require aws/aws-sdk-php
Step 2: Generate AWS keys
Now you need to click on this link to watch the guide for that how to generate aws keys. When we get to the point where we need to set permissions, search for
AmazonSQSFullAccess and select it.
Step 3: Create a Queue
Now in this step head over to your SQS console, click on
Now in this step look out of the box, Laravel dispatches jobs to the
default queue, therefore, your first queue should be named
default on SQS.
If you would be dispatching to a queue other than
default, the queue name should be the same as the queue you're dispatching to.
Now after doing that leave everything else at its default, scroll to the bottom and click on the
create queue button.
Step 4: Set
.env with your preferred text editor. Add set your AWS keys in the following format:
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY AWS_DEFAULT_REGION=YOUR_SQS_REGION
Remember to replace
YOUR_* with the right credentials. Next, set your SQS Prefix:
Finally, change the queue driver to SQS.
Now all are set to go. So run the following command to start your queue worker:
php artisan queue:work sqs
Recommended: Laravel 8.x Queues Example with Redis and Horizon