【问题标题】:AWS Lambda UserMigration_ForgotPassword Trigger | Not Migrating UsersAWS Lambda UserMigration_ForgotPassword 触发器 |不迁移用户
【发布时间】:2020-12-23 17:45:58
【问题描述】:

所以我试图将存储在 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。这是documentation 的链接。仍然出现错误。

【问题讨论】:

  • 嗨 vaquarkhan,感谢您的指点。我添加了“lambda:InvokeFunction”,但没有发生任何事情。当用户忘记密码时,我仍然无法迁移用户
  • 我们已经捕获了用户迁移 lambda,它仅在您单击忘记密码时才起作用,我正在探索无缝迁移将在修复后更新我的答案,可悲的是亚马逊团队没有对 stackoverflow 提供良好的支持并且没有不回答任何问题。
  • 请问,当用户点击忘记密码时,你是如何让它工作的?除了亚马逊(我尝试过以及许多其他口味的)之外,您还有任何文档吗?非常感谢!
  • 我已经分享了我的 lambda 函数,如果你添加 cognito 池 id 并以适当的角色部署,它会在登录时给你错误,所以你需要在你的应用程序中处理三个失败的 attampt 显示忘记密码,一旦用户输入Otp 消息和重置密码用户将移至新池。

标签: node.js amazon-web-services aws-lambda amazon-cognito aws-serverless


【解决方案1】:

触发器为什么不起作用的问题是因为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函数。

我把这个留在这里,以防有人需要帮助!

【讨论】:

    猜你喜欢
    • 2022-08-10
    • 2021-09-08
    • 2018-09-19
    • 1970-01-01
    • 2020-10-02
    • 2019-01-11
    • 2020-05-17
    • 2018-04-02
    • 2017-05-18
    相关资源
    最近更新 更多