通过 EventBridge 规则将用户添加到用户池(任何一个)时是否可以触发 lambda?
最佳答案
可以在 CloudTrail 中记录 AWS Cognito,然后使用 EventBridge 根据来自 AWS Cognito 的 AWS CloudTrail API 中的调用来触发 lambda。
- 需要在 AWS CloudTrail 中设置跟踪,如 Logging Amazon Cognito API calls with AWS CloudTrail 中所述。
- 在 EventBridge 中,您可以从服务 AWS Cognito 用户池和 CloudTrail 中选择事件模式:
- 您可以过滤单个操作要触发的 lambda,例如 AdminCreateUser
过滤 lambda 触发器的支持操作列表,supported operations .
您还可以在 AWS Cognito 中将 lambda 设置为触发器,以便对每个用户操作进行预注册或预身份验证,而不是使用 Event Bridge。
如文档 Customizing user pool workflows with Lambda triggers 中所述:
You can create an AWS Lambda function and then trigger that function during user pool operations such as user sign-up, confirmation, and sign-in (authentication) with a Lambda trigger. You can add authentication challenges, migrate users, and customize verification messages.
要将 lambda 链接为 AWS Cognito 中的触发器:
- Create your lambda if does not exist.
- In AWS Cognito, choose an existing user pool from the list, or create a user pool.
- In your user pool, choose the Triggers tab from the navigation bar.
- Choose a Lambda trigger, such as Pre sign-up or Pre-authentication, and then choose your Lambda function (Created before in AWS Lambda) from the Lambda function drop-down list.
- Choose Save changes.
关于amazon-web-services - 当用户添加到用户池时,Cognito 启动 lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70243226/