问题描述
因此,我试图将存储在dynamodb中的用户迁移到认知用户池,但是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
。这是documentation的链接。仍然出现错误。
解决方法
关于触发器为何不起作用的问题是因为在ClientMetadata
键中未传递任何内容。由于某种原因,我发现文档不够清晰。所以就我而言:
$result = $client->forgotPassword([
'AnalyticsMetadata' => [
'AnalyticsEndpointId' => '<string>',],'ClientId' => '<string>','ClientMetadata' => ['<string>',...],// <- This needs to be filled
'SecretHash' => '<string>','UserContextData' => [
'EncodedData' => '<string>','Username' => '<string>',]);
填充ClientMetadata
键后,它将触发预注册,自定义消息和用户迁移lambda函数。
如果有人需要帮助,我会把它留在这里!