NodeJS中的AWS IOT更新事件验证错误

时间:2016-03-14 07:11:54

标签: node.js amazon-web-services aws-sdk aws-iot

我尝试使用 aws nodejs sdk 更新我的IOT ,但是它给了我“验证错误”异常

代码:

var AWS = require("aws-sdk");
AWS.config.apiVersions = {
  iot: '2015-05-28',
};

var attribs = {};

attribs.type = "Type Value";
attribs.name = "Device Name";

var params = {
   thingName: thing_name,
   attributePayload: {
       attributes: attribs
   }
};

iot.updateThing(params, function(err, data) {
    if (err) {
        console.log(err, err.stack); // an error occurred
    } else {
        console.log(data); // successful response
    }
});

例外:

message: '1 validation error detected: Value \'{name=Device Value, type=Type Value}\' at \'attributePayload.attributes\' failed to satisfy constraint: Map value must satisfy constraint: [Member must have length less than or equal to 1024, Member must have length greater than or equal to 0, Member must satisfy regular expression pattern: [a-zA-Z0-9_.,@/:#-]+]',
  code: 'InvalidRequestException',
  time: Mon Mar 14 2016 07:00:13 GMT+0000 (UTC),
  requestId: '53474c09-e9b2-11e5-a613-a924097ce6cf',
  statusCode: 400,
  retryable: false,
  retryDelay: 44.59372889250517

有没有人知道我的updateThing代码有什么问题?我需要更新Iot的东西

1 个答案:

答案 0 :(得分:0)

IOT事物的属性值不应包含空格

尝试下面的部分

attribs.type = "Type_Value";
attribs.name = "Device_Name";

工作得很好。此外,只有三个属性可以附加到物联网设备。