aws-sdk-php -- Unable to parse error information from response - Error parsing JSON: Syntax error"

96 Views Asked by At

trying to send a sqs on php using aws-sdk, trying to hit a localhost endpoint, we have some lambda functions running on localhost.

This is the client

      $this->client = new SqsClient([
            'credentials' => [
                'key' => $this->key,
                'secret' => $this->secret
            ],
            'region' => $this->region,
            'endpoint' => $this->endpoint,
            'version' => 'latest',
        ]);

And this is the function to send the message

    public function push($queue, $message)
    {
        try {
            $urlResult = $this->client->getQueueUrl([
                'QueueName' => $queue
            ]);

            $result = $this->client->sendMessage([
                'QueueUrl'    => $urlResult['QueueUrl'],
                'MessageBody' => json_encode($message),
            ]);

            return $result;
        } catch (\Exception $e) {
            throw $e;
            return [
                'error' => $e->getMessage(),
                'trace' => $e->getTraceAsString()
            ];
        }
    }

The problem started after we upgrade from sdk v2 to v3. We adapt the code but we still have this issue enter image description here

I've tried using different aws-sdk versions, and also using the debug option on the client, but there was nothing useful. If we downgrade to v2 it works. But we need some v3 functions so it's not an options.

1

There are 1 best solutions below

0
Francisco Mauri On

I had to downgrade to a specific version of aws-sdk-php. 3.277.2 worked for me. It seems before it uses XML api for SQS and now it's JSON, this last one was failing (not sure why tho). https://github.com/aws/aws-sdk-php/discussions/2864