'How to solve "errorMessage": "Cannot read property 'mqtt' of undefined" error in AWS Lambda function for mqtt client authorizer
I am preferring this AWS doc for user/password authentication of MQTT client. I have created such Lambda function with Node.js 14.x runtime to validate the IoT device's (MQTT client) password string with 'test'. Here is the portion of my code,
exports.handler = function(event, context, callback) { 
var uname = event.protocolData.mqtt.username;
var pwd = event.protocolData.mqtt.password;
var buff = new Buffer(pwd, 'base64');
var passwd = buff.toString('ascii');
switch (passwd) { 
    case 'test': 
        callback(null, generateAuthResponse(passwd, 'Allow')); 
    default: 
        callback(null, generateAuthResponse(passwd, 'Deny'));
}
};
While testing the code I got an error like,
"Runtime.ImportModuleError: Error: Cannot find module 'mqtt'"
I think this error is related to the defining of 'mqtt', but I can't get the exact idea about how to resolve it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
