AWS IOT 节点 sdk 为 listThings 和 createThing 提供 ResourceNotFoundException

AWS IOT node sdk gives ResourceNotFoundException for listThings and createThing

我正在尝试获取已注册事物的详细信息并创建新事物。我得到了他们两个的 ResourceNotFoundException。

var AWS = require('aws-sdk');

var iot = new AWS.Iot({
    endpoint: "https://XXXXXXXXXX.iot.us-east-1.amazonaws.com",
    region: "us-east-1",
    accessKeyId: "XXXXXXXXXX",
    secretAccessKey: "XXXXXXXXXX"
});

var params = {
    thingName: 'D02',
    attributePayload: {
        attributes: {
            'Org': 'Org2'
        },
        merge: false
    },
    thingTypeName: 'thing1'
};
iot.createThing(params, function(err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);           // successful response
});

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

至于凭据,我在 IAM 中创建了一个新用户。将编程访问设置为访问类型并附加 AWSIoTFullAccess 权限。

这里有什么问题吗?这可能是什么原因?

整理好了。

它给出 404 或引发 ResourceNotFoundException 因为端点不正确。物联网构造函数必须是这样的。端点应该只是 iot.us-east-1.amazonaws.com.

var iot = new AWS.Iot({
    endpoint: "iot.us-east-1.amazonaws.com",
    region: "us-east-1",
    accessKeyId: "XXXXXXXXXX",
    secretAccessKey: "XXXXXXXXXX"
});