0
votes

I am trying to connect to my "thing" i.e Raspberry Pi registered in my AWS account using node.js. All credential files are stored and located in the proper path (certs folder). aws.iot SDK for node.js is installed on ~/deviceSDK' directory of Raspberry Pi. Here is the code.

var awsIot = require('aws-iot-device-sdk');

var device = awsIot.device({
    keyPath: '/home/pi/deviceSDK/certs/private.pem.key',
    certPath: '/home/pi/deviceSDK/certs/certificate.pem.crt',
    caPath: '/home/pi/deviceSDK/certs/caCert.crt',
    clientId: 'Raspberry',
    region: 'us-west-2'
  });

device.on('connect', function() {
           console.log('connected');
});

When I run the code I received following error:

Error: Invalid connect options supplied.

I googled this problem and figured out that host should be added under connection options. So the code was updated as follows:

var awsIot = require('aws-iot-device-sdk');

    var device = awsIot.device({
        keyPath: '/home/pi/deviceSDK/certs/private.pem.key',
        certPath: '/home/pi/deviceSDK/certs/certificate.pem.crt',
        caPath: '/home/pi/deviceSDK/certs/caCert.crt',
        clientId: 'Raspberry',
        region: 'us-west-2',
        host:   'https://XXXXXXXXXX.iot.us-west-2.amazonaws.com'
    });


    device.on('connect', function() {
           console.log('connected');
    });

In which XXXXXXXXXXX is obviously provided by AWS as Rest API Endpoint to interact with "thing" in my account as following picture shows.

My device endpoint my device endpoint

Now I get this error:

events.js:183 throw er; // Unhandled 'error' event ^

Error: getaddrinfo ENOTFOUND https://xxxxxxxxx.iot.us-west-2.amazonaws.com https://xxxxxxxxxx.iot.us-west-2.amazonaws.com:8883

Any idea what is the problem? Thanks for your help.

2
Can you Raspberry Pi look up other addresses? i.e., if you ssh into it can you do something like nslookup www.google.com?stdunbar

2 Answers

0
votes

The problem was solved by removing https from the host. Thank you.

0
votes

AWS generally throws this error if you're missing any of the key-value pairs for the object required to connect to an IoT device. So if any of the required fields are missing you will get this error.

{
  keyPath: '',
  certPath: '',
  caPath: '',
  host: '',
  clientId: '',
  region: '',
}

Make sure to confirm you've provided all arguments correctly