【发布时间】:2016-11-12 21:51:58
【问题描述】:
我想为我的 AWS Cognito 用户池中的新注册用户制作自定义验证消息
为此,我尝试将 Lamda 函数与“自定义消息”触发器相关联。
但是,我无法找到自定义消息事件的确切格式,无法创建我的 lambda 函数。
我想出的 lambda 函数是
exports.handler = function(event, context) {
//
if(event.userPoolId === "us-east-t9....") {
// Identify why was this function invoked
if(event.triggerSource === "RegisterUser") {
// This Lambda function was invoked because a new user signed up to the user-pool "theRequiredUserPool"
// Ensure that your message contains event.request.codeParameter, this is the place holder for code that will be sent.
var link = "https://.....confirm_user.html?username="+ event.userName + "&code=" + event.request.codeParameter;
var message = "Thank you for signing up. Your confirmation code is " + event.request.codeParameter;
message+= " Click <a href='"+link+"'>here to finish your registatration!";
event.response.emailSubject = "Welcome to the service";
event.response.emailMessage = message;
}
// Create custom message for other events
}
// Customize messages for other user pools
// Return result to Cognito
context.done(null, event);
}
当我在 Lambda 控制台中“测试”我的函数时,它可以工作,但那是因为我正在根据我在文档中找到的唯一线索,针对我自己创建的事件对象对其进行测试:
{ "version": 1,
"triggerSource": "RegisterUser/ResendCode/ForgotPassword/VerifyUserAttribute",
"region": "<region>",
"userPoolId": "<userPoolId>",
"userName": "<userName>",
"callerContext": {
"awsSdk": "<calling aws sdk with version>",
"clientId": "<apps client id>",
...
},
"request": {
"userAttributes": {
"phone_verified": true/false,
"email_verified": true/false,
... (all custom attributes)
},
"codeParameter": "{code}"
},
"response": {
"smsMessage": "<custom message to be sent in the message with code parameter>"
"emailMessage": "<custom message to be sent in the message with code parameter>"
"emailSubject": "<custom email subject>"
}
}
我需要比这更坚固的东西。我无法让我的功能正常工作,我不知道从哪里开始。如果我不知道在事件对象中会发生什么,我该如何实现 lambda 函数? “自定义消息”事件是否有任何规范?
更新: 现在亚马逊用户池已经结束测试,自 2016 年 7 月 29 日起,我不再遇到这个问题。
【问题讨论】:
-
您可以使用
console.log()记录event属性并在CloudWatch 中检查其结构。你知道是否甚至调用了 lambda 吗? Lambda 中的“监控”选项卡应该可以帮助您看到这一点。 -
这是个好主意。@AlexisN-o 不,看起来甚至没有调用 lambda。 :-(
标签: node.js amazon-web-services aws-lambda amazon-cognito