I have created a data migrator using the Laravel v8.x queue system and some batched jobs. For the queue backend, I am using AWS SQS. Without changing any of the code, one day jobs started failing randomly with the following error:
/var/www/data-migrator/vendor/aws/aws-sdk-php/src/AwsClient.php:275
Instances of Aws\Sqs\SqsClient cannot be serialized
The stack trace points to the following line of code which is unchanged:
})->onConnection($queue_conn)->dispatch();
(Previous lines of code just set up the batch, the then
callback, and the catch
callback.)
Over time, the number of these random failures increased until all jobs failed, again without any changes to the code. What is the cause of this error, and how do I fix it?
The answer is that AWS decided to change how its infrastructure and SDK work so that prod deployments that we thought were safe can randomly break. The solution is simple:
$ composer update
$ git add composer.lock
$ git commit -m 'update because bezos'
$ git push
And on the prod instance(s):
$ git pull
$ composer install
$ php artisan queue:restart
This is the second time in a 12 month period that this has happened, and I could not find anything about this error anywhere, so I decided to share the solution here.