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?