3

我用 PHP 编写了一些代码来获取连接到 AWS IoT 服务的 IoT 设备的 ThingShadow 状态。

public function getState($name){
    require_once HOME . DS . 'includes' . DS . 'aws' . DS . 'aws-autoloader.php';
    $IoT = new Aws\IotDataPlane\IotDataPlaneClient([
        'version' => 'latest',
        'region'  => 'us-west-2'
    ]);

    $result = $IoT->getThingShadow([
        'thingName' => $name, // REQUIRED
    ]);

    echo $result["payload"]->getContents();
}

当我在我的本地主机服务器上运行它时,它工作得很好,但是当我在我的 EC2 实例上运行它时它就不起作用了。我调用这个方法,它卡在似乎是一个循环的地方。

我已经检查了凭据,一切都很好。

对于测试,我写错了thingName,我收到以下错误:

Fatal error: Uncaught exception 'Aws\IotDataPlane\Exception\IotDataPlaneException' with message 'Error executing "GetThingShadow" on "https://data.iot.us-west-2.amazonaws.com/things/WRONG_NAME/shadow"; AWS HTTP error: Client error: 404 ResourceNotFoundException (client): No shadow exists with name: 'WRONG_NAME' - {"message":"No shadow exists with name: 'WRONG_NAME'","traceId":"f3c5f1ba-e24a-448d-b4e2-d6265751df87"}' exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: 404' in /var/www/html/includes/aws/GuzzleHttp/Middleware.php:69 Stack trace: #0 /var/www/html/includes/aws/GuzzleHttp/Promise/Promise.php(199): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #1 /var/www/html/includes/aws/GuzzleHttp/Promise/Promise.php(152): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #2 /var/www/html/includes/aws/GuzzleHttp/Promise/TaskQueue.php(60): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() #3 /var/www/html/includes/aws/GuzzleHtt in /var/www/html/includes/aws/Aws/WrappedHttpHandler.php on line 152

当我使用现有事物的实际名称运行代码时,它没有响应。看起来代码在某处循环。

我使用的是 AWS PHP SDK v3。

4

0 回答 0