我正在尝试在AWS中实现自动确认机制,由于Lambda响应,我收到错误。我在文档中找不到正确的返回类型。
LAMBDA:
exports.handler = (event, context, callback) => {
event.response.autoConfirmUser = true;
context.succeed(event.response);
};
例外:
无法识别的lambda输出(服务: AWSCognitoIdentityProviderService;状态代码:400;错误代码: InvalidLambdaResponseException;请求ID: 5c7a2436-0515-11e7-b971-41a89adf53ea)
答案 0 :(得分:15)
如Cognito开发者指南中的PreSignUp trigger example所示,您应该在触发器结束时使用context.done(null, event);
或context.succeed(event);
。
Cognito希望将完整的事件源作为不同Cognito用户池流的一部分调用lambda触发器作为响应。
答案 1 :(得分:2)
很简单。
使用以下代码创建Lambda函数:example
exports.handler = function(event, context) {
/* This Lambda function returns a flag to indicate if a user should be auto-confirmed.
Perform any necessary validations.Impose a condition that the minimum length of the
username of 5 is imposed on all user pools. */
if (event.userName.length < 5) {
var error = new Error('failed!');
context.done(error, event);
}
/* Access your resource which contains the list of emails of users who were invited to
sign up. Compare the list of email IDs from the request to the approved list */
if(event.userPoolId === "yourSpecialUserPool") {
if (event.request.userAttributes.email in listOfEmailsInvited) {
event.response.autoConfirmUser = true;
}
}
// Return result to Cognito
context.done(null, event);
};
注意:角色:Lambda基本执行
TEST 3.使用API创建用户并完成。
答案 2 :(得分:1)
Ruby lambda人,所有Cognito想要返回的都是事件对象。
def lambda_handler(event:, context:)
# TODO implement
return event
end