问题描述
我最近开始使用AWS。我已经使用cognito用户池集成了AWS Amplify用于我的用户管理(登录和注册),并且非常完美(只要有新用户注册,用户池就会更新)。现在我添加了一个Cognito Post确认触发器以将注册的电子邮件保存到数据库中,这是我的触发器代码。var mysql = require('mysql');
I recently started working with AWS. I have integrated AWS Amplify using cognito user pools for my user management(login&signup) and it went perfect(User pool gets updated whenever a new user registers). Now i have added an Cognito Post confirmation trigger to save the registered email into database and here is my trigger codevar mysql = require('mysql');
var config = require('./config.json');
var pool = mysql.createPool({
host : config.dbhost,
user : config.dbuser,
password : config.dbpassword,
database : config.dbname
});
exports.handler = (event, context, callback) => {
let inserts = [event.request.userAttributes.email];
context.callbackWaitsForEmptyEventLoop = false; //prevents duplicate entry
pool.getConnection(function(error, connection) {
connection.query({
sql: 'INSERT INTO users (Email) VALUES (?);',
timeout: 40000, // 40s
values: inserts
}, function (error, results, fields) {
// And done with the connection.
connection.release();
// Handle error after the release.
if (error) callback(error);
else callback(null, results);
});
});
};
每当用户注册并确认其电子邮件时,此触发器就会调用并抛出此错误
无法识别的Lambda输出认知 。即使它在后台抛出此错误,我的数据库也会插入新的注册电子邮件,但是由于此原因,我无法重定向页面。任何帮助将不胜感激。谢谢
whenever a user registers and confirms his email this trigger invokes and throws me this error "Unrecognizable Lambda Output Cognito ". Even though it throws me this error in the background my DB is getting inserted with new registered email, but i am unable to redirect my page due to this. Any help will be appreciated. Thanks
Aravind
推荐答案
简短答案:将 callback(null,results);
替换为 callback(null,event);
原因::您必须返回Cognito将使用它继续进行身份验证工作流的结果。在这种情况下,这是事件
对象。
Reason: You have to return the result that Cognito will use it for continue the authentication workflow. In this case, this is event
object.
这篇关于AWS无法识别的Lambda输出Cognito错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!