Anshuman Upadhyay
Anshuman Upadhyay

Reputation: 103

Getting NULL and Error 403 while trying to subscribe the AWS-IOT custom topic

I have a node application and I am using aws-iot-sdk for establishing a connection to IOT core. I am making a dynamic topic and have a rule for the same that transfers the message to lambda and the lambda does some backend processing. I am now trying to subscribe to the topic in my node app that I am republishing through my rule engine action. I am new to AWS IOT SDK and I am stuck because of the "null" I am getting, please guide me.

I tried to visit the doc of aws-iot-sdk, followed the steps they have written but I am not able to get through the same. If I simply publish and not subscribe in the node app, I am getting the response via SNS, but not able to get back in the app.

My Node code:

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

var name = 'My Thing name';
const TAG = '[' + name + '] >>>>>>>>> ';
const INIT_DELAY = 15;
var app = awsIot.device({
    keyPath: 'My private key',
    certPath: 'My Cert path',
    caPath: 'My Root cert Path',
    clientId: name,
    region: 'the region',
    host: "<host addr>",
});






app.on('connect', () => {
    try{
        app.subscribe('/postacttest/response', (event) => {
            console.log(event);
        });
    } catch(err) {
        console.log(err);
    }

    app.publish('/getacttest/client1', JSON.stringify(
        {
            state: {
                desired: {
                    message: "GET_TEST_RESULT",
                    clientId: "AWSNODECLIENT"
                }
            }
        }
    ));

})

Following is the response I am getting:

null

Following is the rule I am writing on AWS:

SELECT state.desired.clientId AS clientId 
FROM "/getacttest/#" 
WHERE state.desired.message="GET_TEST_RESULT"

Please guide me that how should I subscribe to the topic and show the result as we can do using mqtt.js, that is like WebSocket.

If I configure my connect object as below I am getting the error as shown in the same pic'c terminal area below: Error Dec]

I have written all allow and action policy for my ACT service.

Upvotes: 0

Views: 744

Answers (1)

Anshuman Upadhyay
Anshuman Upadhyay

Reputation: 103

I changed the device config object to have a valid region value. It started working fine.

Upvotes: 0

Related Questions