3

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 ?

Happy Coder
  • 4,255
  • 13
  • 75
  • 152

1 Answers1

9

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.

JW Kim
  • 171
  • 7