我正在像这样扩展我的自定义 Sqs 类:

class Sqs extends SqsClient
{
    public function __construct()
    {
        parent::__construct(array(
            'credentials' => array(
                'key' => $_ENV['AWS_ACCESS_KEY_ID'],
                'secret' => $_ENV['AWS_SECRET_ACCESS_KEY'],
            ),
            'region' => 'us-west-1',
            'version' => 'latest'
        ));
    }
}

然后我实例化并像这样使用它:
$sqs = new Sqs();
$sqs->sendMessage([
    'QueueUrl' => $_ENV['AWS_SQS_URL_PREFIX'] . '/' . $_ENV['AWS_SQS_READER_USER_CREATE'],
    'MessageBody' => $user_json,
    'MessageGroupId' => 1,
    'MessageDeduplicationId' => uniqid(),
]);

但我收到一个奇怪的错误:
The service \"\" is not provided by the AWS SDK for PHP.

最佳答案

AWS API 使用反射来根据类名确定它们连接到的 AWS 服务。如果是这种情况,您可以尝试调用您的类 SqsClient,例如

use Aws\Sqs\SqsClient as BaseSqsClient;

class SqsClient extends BaseSqsClient
{
     //...
}

关于php - 实例化从 AwsClient 子类扩展的类时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48272307/

10-12 06:41