gpt4 book ai didi

node.js - AWS Cognito 用户池的事件触发器对象

转载 作者:搜寻专家 更新时间:2023-11-01 00:06:12 28 4
gpt4 key购买 nike

我想为我的 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>"
}
}

来自 https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html

我需要比这更坚固的东西。我无法让我的功能正常工作,我不知道从哪里开始。如果我不知道在事件对象中期望什么,我该如何实现 lambda 函数? “自定义消息”事件是否有任何规范?

更新:现在,自 2016 年 7 月 29 日起,Amazon 用户池已结束测试版,我不再遇到此问题。

最佳答案

似乎之前的文档中有错误。您能否尝试使用 triggerSource 名称作为“CustomMessage_SignUp”。您还可以查看示例的更新文档。

关于node.js - AWS Cognito 用户池的事件触发器对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38298649/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com