node.js - AWS Lambda UserMigration_ForgotPassword 触发器 | 不迁移用户
问题描述
因此,我试图将存储在 dynamodb 中的用户迁移到 cognito 用户池,但UserMigration_ForgotPassword
触发器根本不起作用。我到处搜索,没有找到解决我问题的方法。我也按照文件来信,仍然没有。这是我的代码在 lambda 中的样子:
else if (event.triggerSource === 'UserMigration_ForgotPassword') {
console.log('forgot password trigger working')
user = await findUser(event.userName)
if (user) {
console.log('user found!')
const { Item } = user
console.log(Item)
event.response.userAttributes = {
'email': Item.email,
'email_verified': Item.emailVerified
}
event.response.messageAction = 'SUPPRESS'
console.log(event)
context.succeed(event);
} else {
console.log('User does not exists')
callback(Error('Bad Password'))
}
这是我在 cloudwatch 上得到的:
2020-09-04T12:13:12.895Z 786f09ce-91b7-4051-ade6-************ INFO forgot password trigger working
2020-09-04T12:13:12.975Z 786f09ce-91b7-4051-ade6-************ INFO user found!
2020-09-04T12:13:12.977Z 786f09ce-91b7-4051-ade6-************ INFO {
emailVerified: true,
password: '************************',
salt: '',
phone_number: '+1111111111',
internal_user_id: '*****',
username: 'name@email.com',
email: 'name@email.com',
name: 'name'
}
2020-09-04T12:13:12.977Z 786f09ce-91b7-4051-ade6-************ INFO {
version: '1',
triggerSource: 'UserMigration_ForgotPassword',
region: 'us-****-*',
userPoolId: 'us-****-*_********',
userName: 'name@email.com',
callerContext: {
awsSdkVersion: 'aws-sdk-unknown-unknown',
clientId: '**************'
},
request: { password: null, validationData: null, userAttributes: null },
response: {
userAttributes: {
email: 'name@email.com',
email_verified: true
},
forceAliasCreation: null,
messageAction: 'SUPPRESS',
desiredDeliveryMediums: null
}
}
我可以安全地得出结论,触发器正在工作,它能够从 dynamodb 获取用户,并且能够构建正确的响应对象。但是,仍然由于某种原因,它无法导入用户。这是我得到的错误:
{code: "UserNotFoundException", name: "UserNotFoundException", message: "Exception migrating user in app client *************************"}
此外,lambda 触发器可以访问 dynamodb,它可以调用函数,它可以登录 cloudwatch,当然,它连接到 cognito 中的触发器。如果您想知道,我正在使用无服务器框架。
最后,我想指出它UserMigration_Authentication
工作正常,这使它变得更加奇怪(至少对我而言)。
很高兴知道问题的根源。
非常感谢!
编辑 1
我不确定这是否与当前的问题有关,但很可能是。我为防止做的另一件事是UserNotFoundException
“启用” PreventUserExistenceErrors
。这是文档的链接。仍然出现错误。
解决方案
关于触发器为什么不起作用的问题是因为ClientMetadata
密钥中没有传递任何内容。出于某种原因,我发现文档不够清晰。所以在我的情况下:
$result = $client->forgotPassword([
'AnalyticsMetadata' => [
'AnalyticsEndpointId' => '<string>',
],
'ClientId' => '<string>',
'ClientMetadata' => ['<string>', ...], // <- This needs to be filled
'SecretHash' => '<string>',
'UserContextData' => [
'EncodedData' => '<string>',
],
'Username' => '<string>',
]);
当ClientMetadata
key被填满时,会触发预注册、自定义消息、用户迁移lambda函数。
我把这个留在这里,以防有人需要帮助!
推荐阅读
- business-catalyst - Adove Business Catalyst 接收不均匀的电子邮件
- javascript - 如何处理重复的输入名称?
- android - 从视频中获取多个缩略图
- kubernetes - 部署扩展不同的部署
- c++ - 在实践中,C++11 中 std::atomic 的内存占用是多少?
- docker - 如何配置 Docker 以便用户只能停止他们启动的容器?
- angular - Angular 5 Component not removed on child route changed
- c# - 找不到路径“/Views/Shared/Error.cshtml”
- php - How to post to google plus profile using api?
- javascript - 根据嵌套数组值过滤数组