AWS Unrecognizable Lambda Output Cognito error

懵懂的女人 提交于 2020-02-04 22:57:58

问题


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);

});

});

};

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


回答1:


Short answer: Replace callback(null, results); to callback(null, event);

Reason: You have to return the result that Cognito will use it for continue the authentication workflow. In this case, this is event object.



来源:https://stackoverflow.com/questions/59650985/aws-unrecognizable-lambda-output-cognito-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!