Cognito后确认功能未触发

发布于 2025-02-08 10:26:01 字数 1030 浏览 2 评论 0原文

我正在使用无服务器和AWS lambda/cognito注册用户,并在用户注册后发送确认电子邮件。为此,我在server> serverless.yml中创建了postenfiration函数>在post postef -Condercration cognito事件之后触发,但是该函数dimn是't似乎完全被打电话。有什么问题?

serverless.yml

...
  postConfirmation:
    description: Cognito handler for when a user is confirmed, here it is used for storing the data to database and sending a confirmation email
    name: "${self:service}-users-post-confirmation-cognito-trigger-${self:provider.stage}"
    handler: src/service/users/postConfirmationTrigger.handler
    dependsOn:
      - CognitoUserPoolMyUserPool
    events:
      - cognitoUserPool:
          pool: ${self:service}-user-pool-${self:provider.stage}
          trigger: PostConfirmation
          existing: true

我正在尝试查看是否完全调用后确认处理程序:

exports.handler =  (event, context, callback)  => {
    console.log(`this function fires!`)
    console.log(event)
}

但是我在日志中看不到任何内容。不确定如何触发处理程序

I'm signing up users to my application using serverless and AWS Lambda/Cognito, and I'd like to send a confirmation email after the users sign up. To do this, I created a postConfirmation function definition in my serverless.yml to be triggered after the postConfirmation Cognito event fires, but that function doesn't seem to get called at all. What could be the issue?

serverless.yml

...
  postConfirmation:
    description: Cognito handler for when a user is confirmed, here it is used for storing the data to database and sending a confirmation email
    name: "${self:service}-users-post-confirmation-cognito-trigger-${self:provider.stage}"
    handler: src/service/users/postConfirmationTrigger.handler
    dependsOn:
      - CognitoUserPoolMyUserPool
    events:
      - cognitoUserPool:
          pool: ${self:service}-user-pool-${self:provider.stage}
          trigger: PostConfirmation
          existing: true

I'm trying to see if the postConfirmation handler is called at all:

exports.handler =  (event, context, callback)  => {
    console.log(`this function fires!`)
    console.log(event)
}

but I don't see anything in the logs. Not sure how to trigger the handler

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

jJeQQOZ5 2025-02-15 10:26:01

看起来像是经典的Lambda回调问题。您的lambda完成回调之前就完成了。尝试一下:

exports.handler =  (event, context, callback)  => {
    console.log(`this function fires!`)
    console.log(event)
    context.done(null, event);
}

或者

exports.handler =  (event, context, callback)  => {
    console.log(`this function fires!`)
    console.log(event)
    callback(null, event);
}

还确保您的lambda配置已设置,以免超时。默认值为3s通常太短。

Looks like a classic Lambda callback issue. Your Lambda is finishing before a callback is completed. Try this:

exports.handler =  (event, context, callback)  => {
    console.log(`this function fires!`)
    console.log(event)
    context.done(null, event);
}

or this

exports.handler =  (event, context, callback)  => {
    console.log(`this function fires!`)
    console.log(event)
    callback(null, event);
}

Also make sure your Lambda configuration is setup so that it doesn't timeout. The default is 3s which is often too short.

┊风居住的梦幻卍 2025-02-15 10:26:01

确认后的lambda被触发时,当用户被确认不仅是注册时,
因此,通过使用控制台设置自动化电子邮件后,请确保用户在注册后验证他的电子邮件或电话号码:

“在此处输入图像说明”

或使用serverless:

Resources:
  CognitoUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      UserPoolName: user-pool
      # Set email as an alias
      UsernameAttributes:
        - email
      AutoVerifiedAttributes:
        - email  <--- HERE

PostConfirmation Lambda is triggered when the user is confirmed not only signup,
so make sure that the user verifies his email or phone number after signup by setting autoVerify email using console:

enter image description here

Or using serverless:

Resources:
  CognitoUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      UserPoolName: user-pool
      # Set email as an alias
      UsernameAttributes:
        - email
      AutoVerifiedAttributes:
        - email  <--- HERE
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文