CMo*_*udy 6 eventtrigger amazon-web-services amazon-cognito aws-lambda serverless-framework
使用无服务器框架创建 Cognito 用户池以及用于 TOPT SMS 授权期间的 cognito 事件的多个 lambda。一切都已创建,但 lambda 函数未在 Cognito 中注册。
对于无服务器来说相对较新,但似乎无法让它们连接起来。已尝试池名称,正如其他人尝试将其标记为在创建结束时已存在一样,池已存在且 lambda 也已存在,但没有连接。
目前,在另一篇文章之后尝试将用户池更改为 CognitoUserPoolMyUserPool,然后在 lambda 中将其引用为 MyUserPool。还在这两个位置尝试了 CognitoUserPool,但都不起作用。
serverless.yaml 文件示例:
service: cognito-authentication
frameworkVersion: ">=1.1.0 <2.0.0"
package:
individually: false
plugins:
- serverless-bundle
custom:
stage: ${opt:stage, self:provider.stage}
poolName: ${self:custom.stage}-user-pool
provider:
name: aws
runtime: nodejs10.x
stage: dev
iamRoleStatements:
- Effect: Allow
Action:
- sns:*
Resource:
- "*"
functions:
preSignUp:
handler: functions/pre-signup.main
events:
- cognitoUserPool:
pool: MyUserPool
trigger: PreSignUp
defineAuthChallenge:
handler: functions/define-auth-challenge.main
events:
- cognitoUserPool:
pool: MyUserPool
trigger: DefineAuthChallenge
createAuthChallenge:
handler: functions/create-auth-challenge.main
events:
- cognitoUserPool:
pool: MyUserPool
trigger: CreateAuthChallenge
verifyAuthChallengeResponse:
handler: functions/verify-auth-challenge-response.main
events:
- cognitoUserPool:
pool: MyUserPool
trigger: VerifyAuthChallengeResponse
resources:
Resources:
CognitoUserPoolMyUserPool:
Type: "AWS::Cognito::UserPool"
Properties:
# Generate a name based on the stage
UserPoolName: ${self:custom.poolName}
# Set phone_number as an alias
UsernameAttributes:
- phone_number
Policies:
PasswordPolicy:
MinimumLength: 6
RequireLowercase: False
RequireNumbers: False
RequireSymbols: False
RequireUppercase: False
CognitoUserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
# Generate an app client name based on the stage
ClientName: ${self:custom.stage}-sms-auth-client
UserPoolId:
Ref: CognitoUserPoolMyUserPool
ExplicitAuthFlows:
- CUSTOM_AUTH_FLOW_ONLY
GenerateSecret: false
Run Code Online (Sandbox Code Playgroud)
预期用户池已正确创建并配置为使用 lambda 来触发工作流执行。
我已经复制粘贴了您的代码(并添加了相关的 Lambda 函数),它对我有用。
PreSignUp我已经使用以下命令
进行了测试:aws cognito-idp admin-create-user --region <region> --user-pool-id <user-pool-id> --username <phone>
虽然没有显示在 AWS 控制台 Lambda UI 中,但触发器确实显示在 Cognito->用户池->开发用户池->触发器中,这令人困惑。
示例仓库: https: //github.com/erezrokah/serverless-cognito-triggers
| 归档时间: |
|
| 查看次数: |
6548 次 |
| 最近记录: |