gpt4 book ai didi

aws-lambda - Cognito 用户池不调用 lambda 函数

转载 作者:行者123 更新时间:2023-12-03 07:15:25 25 4
gpt4 key购买 nike

我正在使用 Cloudformation 创建 Cognito 用户池,并将 LambdaConfig -> PreAuthentication 设置为同样使用 Cloudformation 创建的 Lambda 函数。问题是 Lambda 函数似乎没有被调用。进行身份验证时,用户无需 PreAuthentication 逻辑的干预即可登录,并且 lambda 函数的 Cloudwatch 日志为空。如果我在 Lambda 仪表板中测试该函数,它会正常运行。我没有收到任何错误。

此外,我正在基于有效的现有设置对此 Cloudformation 设置进行建模。 Cloudformation 堆栈生成的资源似乎与工作版本具有相同的配置。

cloudformation 模板的相关部分如下所示:

  UserPool:
Type: AWS::Cognito::UserPool
Properties:
LambdaConfig:
PreAuthentication: !GetAtt UserAuthorizerFunction.Arn
UsernameAttributes:
- email
UsernameConfiguration:
CaseSensitive: false

Lambda 函数的定义如下:

  UserAuthorizerFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: Authorize_Users
Description: Authorizes users
Handler: index.handler
Role: !GetAtt AuthorizerFunctionRole.Arn
Code:
ZipFile: |
const AWS = require('aws-sdk')
// stuff
Runtime: nodejs12.x

lambda 函数是使用基于资源的策略创建的,看起来是正确的:

{
"Version": "2012-10-17",
"Id": "default",
"Statement": [
{
"Sid": "AuthorizerFunctionPermission-WSIGC4MBBT0C",
"Effect": "Allow",
"Principal": {
"Service": "cognito-idp.amazonaws.com"
},
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:us-east-1:<redacted>:function:Authorize_Users",
"Condition": {
"ArnLike": {
"AWS:SourceArn": "arn:aws:cognito-idp:us-east-1:<redacted>:userpool/us-east-1_<redacted>"
}
}
}
]
}

为什么我的 PreAuthentication Hook 没有被执行?是否存在我没​​有想到的 DependsOn 要求?

最佳答案

事实证明这是一个已知问题 - 至少其他人正在经历它: https://forums.aws.amazon.com/thread.jspa?messageID=897845&#897845

我需要删除 ALLOW_CUSTOM_AUTH 身份验证流程选项并使用 ALLOW_USER_PASSWORD_AUTH

关于aws-lambda - Cognito 用户池不调用 lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65986287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com