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
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.
nslookup www.google.com
? – stdunbar