How to use Amazon SQS as the queue driver in Laravel?

To use Amazon SQS as the queue driver in Laravel, you need to follow these steps:

  1. Install the AWS SDK for PHP: Install the AWS SDK for PHP using Composer by running the command composer require aws/aws-sdk-php.

  2. Configure the AWS credentials: Set up your AWS credentials by updating the config/aws.php file or by adding the following environment variables:

    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    • AWS_DEFAULT_REGION
  3. Update the config/queue.php file: Open the config/queue.php file and set the driver to sqs. Make sure to also fill in the key, secret, queue, and region values as per your AWS SQS configuration.

'default' => env('QUEUE_CONNECTION', 'sqs'), 'connections' => [ 'sqs' => [ 'driver' => 'sqs', 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 'queue' => env('SQS_QUEUE', 'your-queue-name'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), ], ],
  1. Set up your Laravel application to use the SQS driver: Open the .env file and update the QUEUE_CONNECTION value to sqs.
QUEUE_CONNECTION=sqs
  1. Run the queue workers: Start the Laravel queue workers by running the command php artisan queue:work or by setting up a queue listener in your server configuration.

Now, Laravel will use Amazon SQS as the queue driver, and you can push jobs onto the SQS queue using Laravel's queue API.