Aws iot struggling with getting things shodow

I know that I am missing something basic, but I'm really stuck trying to access the shadow shadow system on the AWS IOT platform.

I use the following code to create a new thing:

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

The above code successfully creates a thing. I see a thing created at startup:

 $awsIoTClient->listThings(); 

Then, when I try to access the shadow tag with the following code:

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

I get the following error:

 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). 

Compatible things: The user whose access and secret keys are used to create this thing have the following AWS rules (we will block them as soon as we get this):

 - AWSIoTLogging - AWSIoTConfigAccess - AWSIoTRuleActions - AWSIoTConfigReadOnlyAccess - AWSIoTDataAccess - AWSIoTFullAccess 
+5
source share
1 answer

Refuses, you need to update the shadow before you can update it.

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

After that, it will return the shadow:

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

Source: https://habr.com/ru/post/1236557/


All Articles