AWS IOT挣扎着让事情变得蠢蠢欲动

时间:2015-11-22 16:07:59

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

我知道我在这里遗漏了一些基本内容,但我真的很难在AWS IOT的平台上尝试访问一些东西。

我正在使用以下代码创建新内容:

NODE_ENV=production forever start index.js

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

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策略(一旦我们开始工作,我们将锁定这些策略):

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

0 个答案:

没有答案