【问题标题】:How to pass the validation code to the Lambda function如何将验证码传递给 Lambda 函数
【发布时间】:2019-09-09 06:40:21
【问题描述】:

我正在尝试自定义用户忘记密码时 AWS Cognito 发送的电子邮件。

它需要 {####} 占位符作为电子邮件中的验证码。例如,如果你这样做 event['response']['emailMessage'] = "Your code is {####}",你会收到一条消息Your code is 123456

这是我的 AWS Lambda 函数的示例:

def custom_message_handler(event, context):
    event['response']['emailSubject'] = 'Custom subject'
    event['response']['emailMessage'] = 'Custom email'
    # verification_code = event[...] ???
    return event

在您的 lambda 返回带有占位符的消息后,Cognito 似乎会生成验证码。是否可以在你的 lambda 中获取验证码以使用它?

【问题讨论】:

  • 很遗憾,无法在 Lambda 函数中使用数字验证码。
  • @lightyagami 您可以发表您的评论作为答案。

标签: aws-lambda amazon-cognito


【解决方案1】:

Amazon Cognito 的自定义消息 Lambda 触发器的事件 JSON 未获取数字验证码。触发器可用的Event的数据,如official documentation中所述,说明如下:

{
  "version": 1,
  "triggerSource": "CustomMessage_AdminCreateUser",
  "region": "<region>",
  "userPoolId": "<userPoolId>",
  "userName": "<userName>",
  "callerContext": {
      "awsSdk": "<calling aws sdk with version>",
      "clientId": "<apps client id>",
      ...
  },
  "request": {
      "userAttributes": {
          "phone_number_verified": false,
          "email_verified": true,
           ...
      },
      "codeParameter": "####",
      "usernameParameter": "username"
  },
  "response": {
      "smsMessage": "<custom message to be sent in the message with code parameter and username parameter>"
      "emailMessage": "<custom message to be sent in the message with code parameter and username parameter>"
      "emailSubject": "<custom email subject>"
  }
}

只有当 Cognito 数据在 Event 中可用时,或者有单独的 API 调用时,您才能在 Lambda 触发器中使用 Cognito 数据。但鉴于 Amazon Cognito 的设计,这似乎是不可能的。

【讨论】:

  • 感谢您的澄清
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-10
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多