0
votes

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.

1
The syntax for the policy is quirky - can you include the contents of your policy in the post?Ben T
This issue has been instilling restlessness in me for 2 days..however I came around the resolve by having a look again at my device config object, where I have mentioned region as us-west-2b instead of us-west-2..corrected it and working fine..what a lame mistake..though it made to learn and see websites.. :).. Thanks @blt for taking out time to read my questionAnshuman Upadhyay

1 Answers

0
votes

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