Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS IOT node sdk gives ResourceNotFoundException for listThings and createThing

I'm trying to get details of the registered things and create new things. I get ResourceNotFoundException for both of them.

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

As for the credentials, I created a new user in IAM. Set Programmatic access as Access Type and attached AWSIoTFullAccess permission.

Is there anything wrong here? What could be the reason for this?

like image 588
Hashan Seneviratne Avatar asked Dec 10 '25 03:12

Hashan Seneviratne


1 Answers

Got it sorted out.

It was giving 404 or raising ResourceNotFoundException because endpoint was incorrect. IoT constructor would have to be like this. Endpoint should be just 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"
});
like image 140
Hashan Seneviratne Avatar answered Dec 11 '25 18:12

Hashan Seneviratne