Credentials must be an instance of Aws\\Credentials\\CredentialsInterface error on PHP SDK with SQS
Asked Answered
W

1

5

I am trying to delete a message from SQS in AWS using the php SDK. I have the following configuration.

$sqsClient = new SqsClient([
            'version' => '2012-11-05',
            'region'  => 'us-east-1',
            'credentials' => [
                'key' => KEY,
                'secret' => SECRET
            ]
        ]);

Then I am trying to delete like the following :

$sqsClient->deleteMessage([
                'QueueUrl' => quque-url
                'ReceiptHandle' => handle
            ]);

I am getting the following error on initialization :

Credentials must be an instance of Aws\\Credentials\\CredentialsInterface, an associative array that contains \"key\", \"secret\", and an optional \"token\" key-value pairs, a credentials provider function, or false."

The credentials I am using is correct. Before I was not passing the config and then also the same error was appearing. How this can be fixed ?

Watters answered 9/9, 2019 at 9:2 Comment(0)
J
10

I found this code example and I think your code is correct.

How about create instance of Credentials?

You can use these code for initiating instance.

$credentials = new Aws\Credentials\Credentials(KEY, SECRET);
$sqsClient = new SqsClient([
            'version' => '2012-11-05',
            'region'  => 'us-east-1',
            'credentials' => $credentials
        ]);

Check this document.

And for security reason, I recommend that you'd better use credentials file or set environment variable.

I hope all is well.

Jarredjarrell answered 11/9, 2019 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.