gpt4 book ai didi

amazon-web-services - AWS IOT 挣扎于获取事物的阴影

转载 作者:行者123 更新时间:2023-12-04 19:52:35 24 4
gpt4 key购买 nike

我知道我在这里遗漏了一些基本的东西,但我真的很难在 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).

需要注意的几点:
使用其访问 key 和 key 来创建此事物的用户具有以下 AWS 政策(一旦我们开始工作,我们将锁定这些政策):
- AWSIoTLogging
- AWSIoTConfigAccess
- AWSIoTRuleActions
- AWSIoTConfigReadOnlyAccess
- AWSIoTDataAccess
- AWSIoTFullAccess

最佳答案

事实证明,答案是您需要先更新阴影,然后才能阅读它。

$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
]);

关于amazon-web-services - AWS IOT 挣扎于获取事物的阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33856946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com