【问题标题】:AWS IOT Struggling with getting thing shodowAWS IOT 难以获得阴影
【发布时间】:2016-02-24 17:27:12
【问题描述】:

我知道我在这里遗漏了一些基本的东西,但我真的被困在试图访问 AWS IOT 平台上的东西影子。

我正在使用以下代码来创建一个新事物:

use Aws\Iot\IotClient;
$thingName = '<string uuid>';
$awsIoTClient = new IotClient([
    'version' => 'latest',
    'region' => <region>,
    'credentials' => [
      'key'    => <aws_access_key>,
      'secret' => <aws_secret_key>,
    ]
]);
$policyName = 'Global_Hub_Policy';
// # !---------------------------
// # !- Implementation
// # !---------------------------
$result = $awsIoTClient->createThing([
    'thingName' => $thingName,
]);
$result = $awsIoTClient->createKeysAndCertificate([
    'setAsActive' => TRUE,
]);
$certArn = $result['certificateArn'];
$certId = $result['certificateId'];

$certPem = $result['certificatePem'];
$privateKey = $result['keyPair']['PrivateKey'];
$awsIoTClient->attachPrincipalPolicy([
        'policyName' => $policyName,
        'principal' => $certArn
]);
$awsIoTClient->attachThingPrincipal([
        'principal' => $certArn,
        'thingName' => $thingName
]);

上面的代码成功创建了一个东西。我可以看到我运行时创建的东西:

$awsIoTClient->listThings();

然后当我尝试使用以下代码访问事物的影子时:

Use Aws\IotDataPlane\IotDataPlaneClient;
$client = new IotDataPlaneClient([
    'version' => 'latest',
    'region' => <region>,
    'credentials' => [
      'key'    => <aws_access_key>,
      'secret' => <aws_secret_key>,
    ]
]);
$result = $client->getThingShadow([
  'thingName' => '<string uuid>', // REQUIRED
]);

我收到以下错误:

Aws\IotDataPlane\Exception\IotDataPlaneException: Error executing "GetThingShadow" on "https://data.iot.us-east-1.amazonaws.com/things/<string uuid>/shadow"; AWS HTTP error: Client error: 404 ResourceNotFoundException (client): No shadow exists with name: '<string uuid>' - {"message":"No shadow exists with name: '<string uuid>'","traceId":"<traceId>"} in Aws\WrappedHttpHandler->parseError() (line 152 of /<docroot>/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php).

需要注意的几点: 使用其访问和密钥来创建这个东西的用户具有以下 AWS 策略(一旦我们开始工作,我们将锁定这些策略):

- AWSIoTLogging
- AWSIoTConfigAccess
- AWSIoTRuleActions
- AWSIoTConfigReadOnlyAccess
- AWSIoTDataAccess
- AWSIoTFullAccess

【问题讨论】:

    标签: amazon-web-services aws-sdk aws-iot


    【解决方案1】:

    答案是你需要更新阴影才能阅读它。

    $json = json_encode(['state' => ['desired' => ['test_updated' => "date updated " . date('r')]]]);
    $result = $client->getThingShadow([
      'thingName' => $thingname,
      'payload' => $json,
    ]);
    

    之后,这将返回一个影子:

    $result = $client->getThingShadow([
      'thingName' => '<string uuid>', // REQUIRED
    ]);
    

    【讨论】:

    • "你需要更新影子才能更新它" >你的意思是“你需要更新影子才能阅读它”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    相关资源
    最近更新 更多