使用MQTT用户名密码连接AWS IoT Core失败求助
AWS IoT Core 用户名密码自定义认证连接失败问题
我尝试通过用户名密码实现AWS IoT Core的自定义认证,但连接失败,具体操作如下:
- 尝试创建不依赖X.509证书、基于443端口的自定义认证
- 按照AWS官方自定义认证配置步骤操作,针对MQTT用户名登录场景做了适配修改
- 已完成Authorizer配置,关联的Lambda函数ARN正确,函数代码如下:
// A simple Lambda function for an authorizer. 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')); } }; // Helper function to generate the authorization response. var generateAuthResponse = function(token, effect) { var authResponse = {}; authResponse.isAuthenticated = true; authResponse.principalId = 'TEST123'; var policyDocument = {}; policyDocument.Version = '2012-10-17'; policyDocument.Statement = []; var publishStatement = {}; var connectStatement = {}; connectStatement.Action = ["iot:Connect"]; connectStatement.Effect = effect; connectStatement.Resource = ["arn:aws:iot:eu-west-1:<myarn>:client/myClientName"]; publishStatement.Action = ["iot:Publish"]; publishStatement.Effect = effect; publishStatement.Resource = ["arn:aws:iot:eu-west-1:<myarn>:topic/telemetry/myClientName"]; policyDocument.Statement[0] = connectStatement; policyDocument.Statement[1] = publishStatement; authResponse.policyDocuments = [policyDocument]; authResponse.disconnectAfterInSeconds = 3600; authResponse.refreshAfterInSeconds = 300; return authResponse; }
- 使用AWS CLI测试认证流程一切正常,但通过Node-RED和Mosquitto客户端尝试连接时均失败
内容的提问来源于stack exchange,提问作者serkan ersoy
相关产品推荐
相关产品推荐

