AWS Lambda UserMigration_ForgotPassword 触发器 |不迁移用户
AWS Lambda UserMigration_ForgotPassword Trigger | Not Migrating Users
所以我试图将存储在 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
。这里有一个link到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函数。
我把它留在这里以防有人需要帮助!
所以我试图将存储在 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
。这里有一个link到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函数。
我把它留在这里以防有人需要帮助!