AWS 物联网:ForbiddenException:禁止

AWS IoT: ForbiddenException: Forbidden

我在尝试 getThingShadow() 方法时遇到错误。

没有Node.js,只是普通的Javascript。

相关代码:

var params = {
  thingName: 'test123'
};
var iotdata = new AWS.IotData({
  accessKeyId: AWS.config.credentials.accessKeyId,
  secretKey: AWS.config.credentials.secretAccessKey,
  sessionToken: AWS.config.credentials.sessionToken,
  region: AWSConfiguration.region, 
  endpoint: AWSConfiguration.host
});

iotdata.getThingShadow(params, function (err, data) {
  if (err) {
    console.log(err, err.stack); 
  } 
  else {
    console.log(data);         
  }
});

错误信息:

GET https://XXX.eu-central-1.amazonaws.com/things/test123/shadow

[HTTP/1.1 403 Forbidden 106ms] ForbiddenException: Forbidden

Stack-Trace: //many many lines of unrelevant text

我的 IAM 规则:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iot:Publish",
        "iot:Subscribe",
        "iot:Connect",
        "iot:Receive",
        "iot:UpdateThingShadow",
        "iot:GetThingShadow"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

你可能会看到,我几乎允许了所有内容,但我仍然收到禁止例外,为什么? 顺便说一句:用户身份验证 (AWS-Cognito) 成功,我收到了所有需要的凭据。

通过 IoT Web 控制台(手动)将 cognitoID 附加到策略解决了这个问题,并且有效。