【问题标题】:Disable User in Post Confirmation Trigger在确认后触发器中禁用用户
【发布时间】:2020-12-21 02:48:19
【问题描述】:

我有一个不同类型的用户群(user_type 属性将定义类型)。我想在确认后禁用某些类型的用户。即流程:用户注册 --> 用户收到带有代码的确认电子邮件 --> 用户输入代码 --> 后确认触发器被调用。

这是我的帖子确认触发器 lambda:

import logging
import boto3

logger = logging.getLogger()
logger.setLevel(logging.INFO)

cognito_client = boto3.client('cognito-idp')

def lambda_handler(event, context):
    user_type =  event['request']['userAttributes'].get('user_type', '')
    logger.info(event)
    if user_type == 'TYPE1':
        response = cognito_client.admin_disable_user(
            UserPoolId=event['userPoolId'],
            Username=event['userName']
        )
        logger.info(response)
    return event

这会返回以下错误:

botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the AdminDisableUser operation: User: arn:aws:sts::<accound_id>:assumed-role/CognitoPostConfirmation-role-xxxxx/CognitoPostConfirmation is not authorized to perform: cognito-idp:AdminDisableUser on resource: arn:aws:cognito-idp:us-east-1:xxxxxx:userpool/us-east-1_xxxxxx

有没有办法禁止某些类型的用户使用触发器?我也尝试使用预注册,但这里的问题是所有其他类型的用户都需要自动确认,这不是我想要的。我需要普通用户接收确认电子邮件,而某种类型的用户要么收到确认,然后被禁用,要么一开始就没有被确认。

非常感谢您对此提供任何帮助

谢谢,

【问题讨论】:

    标签: python aws-lambda amazon-cognito amazon-cognito-triggers


    【解决方案1】:

    每个 Lambda 函数都有一个执行角色,它承担该角色以获得允许它进行所需的所有 AWS API 调用的权限。

    从错误消息来看,您的 Post Confirmation Trigger 的 Lambda 函数似乎有一个名为 CognitoPostConfirmation 的执行角色。

    错误消息告诉您它没有正确的权限来运行您用来禁用某些用户的 cognito-idp:AdminDisableUser 方法。

    因此,您应该转到 IAM 并向 CognitoPostConfirmation 角色添加一个策略,以允许您的 lambda 函数使用该 API 方法:

    {
        "Effect": "Allow",
        "Action": "cognito-idp:AdminDisableUser",
        "Resource": "arn:aws:cognito-idp:<your-aws-region>:<your-aws-account>:userpool/<your-userpool-id>"
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-06
      • 2020-10-09
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 2013-02-09
      • 2021-05-27
      • 1970-01-01
      • 2011-09-23
      相关资源
      最近更新 更多